I have 3 fields (ln, fn & dob) whose Required Property is set to Yes. I would like to check the database after entering data in the 3 fields that would alert me if any duplicates being entered.
I have entered the following code in the BeforeUpdate property of control “dob” that I want to validate before adding a new record.
Private Sub dob_BeforeUpdate(Cancel As Integer)
Dim Msg, Style, Title, Response, Counter
Msg = “A duplicate record may exist.” + Chr(13) + “Do you want to add client anyway?” ‘Message Displayed
Style = vbYesNo + vbCritical + vbDefaultButton2 ‘Define Buttons
Title = “Duplicate Client Message” ‘Define Title
Response = MsgBox(Msg, Style, Title)
Counter = DCount(“clientid”, “client”, “fn =” & Chr(34) & Me.[fn] & Chr(34) & _
” And ln=” & Chr(34) & Me.[ln] & Chr(34) & _
” And dob=#” & Me.dob & “#”)
If Response = vbNo Then ‘User chose No
Cancel = True
DoCmd.GoToControl (“ln”)
Else ‘User chose Yes
DoCmd.GoToControl (“gender”)
End If
End Sub
No matter whether I choose Yes or No, I continue to get run time error 2108. Can anyone help me correct this?