How do I do this in Access 2007?

B

Big Pepper

Hi,
I have Access database has a customer table.
The customer table has a customerID field datatype is autonumber (prim. key).
I made a CustomerEntry form base on customer table.
On customerEntry form has a textBox lookupCustID field.
What should I do if I enter a value in lookupCustID, onexit event it
lookupCustID exist customerID in customer table then display that customer
record.
If not exist then goto the new record.

Thanks for any help,
Mimy
 
B

Beetle

The text box should be unbound. In its After Update event (not its Exit
event) you would have code like;

Private Sub lookupCustID_AfterUpdate()

With Me.RecordsetClone
.FindFirst "customerID = " & Me.lookupCustID
If Not .NoMatch Then
Me.Bookmark = .Bookmark
Else
MsgBox "No matching customer found"
DoCmd.GoToRecord , , acNewRec
End If
End With

End Sub


A more user friendly option might be to use a combo box to allow
users to choose from a list of customers, so they don't always have to
know the CustomerID. You could use the same basic approach as above
to have your form move to the correct record after they make a selection
in the combo box.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top