Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If Statement not working like I thought it would

Status
Not open for further replies.

kb178

IS-IT--Management
Aug 16, 2001
83
US
Hi Everyone! I have this code that executes after the [Last Name] field is updated:

Private Sub Last_Name_AfterUpdate()
DoCmd.RunCommand acCmdSaveRecord
If Not IsNull(DLookup("ID", "[Reg Form]", "[First Name]=Forms![Reg Form]![First Name] AND [Last Name] = Forms![Reg Form]![Last Name]")) Then
Response = MsgBox("The attendee name you have just entered is a duplicate. Click the 'Search' button now to find the attendee.", vbOKOnly)
End If
End Sub

I get the messagebox to come up when a first name and last name is duplicated - however I also get the message when they are not duplicated! Any ideas on how to correct this code? Thank you!!!
 
Just want to add on that Reg Form is the table name as well as the form name...
 
Ok, besides the obvious lecture on not naming your tables and forms the same (at least use Hungarian notation) your easiest be here would be too create a "Find Duplicates" query (use the wizard) and point your DLookup there. If anything sshows up, then it's a dup, otherwise it's not.

If Not IsNull(DLookup("ID", "[qryFindRegFormDups]", "[First Name]=Forms![Reg Form]![First Name] AND [Last Name] = Forms![Reg Form]![Last Name]")) Then
Kyle [pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top