Re: Lookup and/or create new record from same box?
- From: "Mike" <webmaster@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 18 Jan 2008 09:13:11 -0600
Thanks for the quick responses. I'll give these a shot and let you know if was able to get it to work or not :)
Mike
"Klatuu" <Klatuu@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:5D428E97-0DAF-48AB-AA7D-9255B8CE58EC@xxxxxxxxxxxxxxxx
This is a very common situation. What you are calling a lookup box is, I
think, a Combo Box.
The typical technique is to use the After Update event of the combo to find
an existing record and navigate to it if it exists.
With Me.RecordsetClone
.FindFirst "[ID] = " & Me.MyCombo
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
Now when you want to add a new record if the ID doesn't exist in the table,
set the combo's Limit To List property to Yes. If you enter an ID that is
not in the list, the Not In List Event will fire. Here is an example of how
you add the new record or not depending on user input:
If MsgBox(NewData & " Is Not In The Customer Table " & vbNewLine _
& "Do you want to add it", _
vbInformation + vbYesNo, "Not Found") = vbYes Then
Me.MyCombo = MeMyCombo.OldValue
CurrentDb.Execute ("INSERT INTO Customer Table Table ([ID]) " _
& "VALUES ('" & NewData & "');"), dbFailOnError
Me.Requery
With Me.RecordsetClone
.FindFirst "[Activity] = '" & NewData & "'"
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
Response = acDataErrAdded
Else
Me.MyCombo.Undo
Response = acDataErrContinue
End If
--
Dave Hargis, Microsoft Access MVP
"Mike" wrote:
Here's what i'm trying to achieve.
I want people to be able to look up a client by their unique ID number. I
know this is easily achievable through a lookup box. Not a big deal, i know.
What i'd really like to do, is to be able to type in the said number and
have it search the table for that record and go to it, if it exists. If it
doesn't exist, i'd like it to tell the user that the record doesn't exist,
but prompt them with a yes/no box (or something) to create a record with
that ID if they like. Then, pass that ID on to the new record.
Is this even possible? Or is there a better/simpler way that i'm not even
thinking of?
Thanks
Mike
.
- References:
- RE: Lookup and/or create new record from same box?
- From: Klatuu
- RE: Lookup and/or create new record from same box?
- Prev by Date: RE: Edit Calculated Text Field
- Next by Date: RE: Edit Calculated Text Field
- Previous by thread: RE: Lookup and/or create new record from same box?
- Next by thread: Re: Lookup and/or create new record from same box?
- Index(es):
Relevant Pages
|