Below is code for checking for duplicates of a surname at a school.
"duplicates" is a query with school criteria used from the open form
It Shows the message box if there are duplicates or not. The only time the message doesn't show is when the surname text box is left blank.
Can someone explain my error?
"duplicates" is a query with school criteria used from the open form
Code:
Private Sub Surname_LostFocus()
Dim counter As Long
counter = DCount("*", "duplicates", "Surname = [Forms]![frmSchools]![frmContacts].[Form]![surname]")
If counter > 0 Then
MsgBox "There is a contact at this school with this surname. Please ensure they are different people. ", vbExclamation, " Possible Duplication Error"
End If
End Sub
It Shows the message box if there are duplicates or not. The only time the message doesn't show is when the surname text box is left blank.
Can someone explain my error?