combining duplicate and null code

Gazza2

Registered User.
Local time
Yesterday, 23:39
Joined
Nov 25, 2004
Messages
184
I have a text box that is used to enter a customers name.I have this code on the lostfocus event : If Len(Me.Customer) > 0 Then
MsgBox "message"
Cancel = True
Me.Undo
End if

This works ok except after the ok button is clicked it doesn't return to the customer text box.
I also have the following code in the Beforeupdate event :
If DCount("Customer", "Table6", "Customer=""" & Forms!Form8!customer & """") = 0 Then
MsgBox "Customer already exist", , "Duplicate Error"
Cancel = True
Me.Undo
End If

This also works fine and returns to the customer text box after clicking the ok button.

My questions are is there a way to combine this code into the beforeupdate event or is this the best way to do it, If it is the best way to do it how can i make the lostfocus event return to the correct text box.

Thanks in advance.
 
Code:
If DCount("Customer", "Table6", "Customer=""" & Forms!Form8!customer & """") = 0 Then
    MsgBox "Customer already exist", , "Duplicate Error"
      Cancel = True
      Me.Undo
    Me.Customer.SetFocus
End If
 
What are you actualy trying to achieve?

surely this will fire if there are no matches not if the customer exists?

If DCount("Customer", "Table6", "Customer=""" & Forms!Form8!customer & """") = 0 Then

Peter
 
basically i have a text box for customers name and i want a message to pop up saying that a name is needed if the user goes to the next text box ( by pressing enter or tab) and also a different messag saying that the name already exists if the user enters a duplicate name.
 

Users who are viewing this thread

Back
Top Bottom