I'm currently using a DLookup for a form so that the user can't enter a duplicate customer record. Normally it works fine, but when I try to enter in a name with an apostrophe (i.e., O'Neill or O'Donnell), I get an error message. Can anyone help me with this? Here's the code I'm using:
Private Sub ContactLastName_BeforeUpdate(Cancel As Integer)
Dim Response As Integer
If Not IsNull(DLookup("[ContactLastName]", "Customers", "[ContactLastName]= '" & Me.ContactLastName & "' And [ContactFirstName] = '" & Me.ContactFirstName & "'")) Then
Response = MsgBox("There is already someone with the same First and Last name in the " & _
"table." & vbCr & vbCr & "Select Yes to continue, No to start again.", vbCritical + _
vbYesNo + vbDefaultButton2, "Duplicate Data")
If Response = vbYes Then
Exit Sub
Else 'vbNo (Default)
Me.Undo
Cancel = True
End If
End If
End Sub
Private Sub ContactLastName_BeforeUpdate(Cancel As Integer)
Dim Response As Integer
If Not IsNull(DLookup("[ContactLastName]", "Customers", "[ContactLastName]= '" & Me.ContactLastName & "' And [ContactFirstName] = '" & Me.ContactFirstName & "'")) Then
Response = MsgBox("There is already someone with the same First and Last name in the " & _
"table." & vbCr & vbCr & "Select Yes to continue, No to start again.", vbCritical + _
vbYesNo + vbDefaultButton2, "Duplicate Data")
If Response = vbYes Then
Exit Sub
Else 'vbNo (Default)
Me.Undo
Cancel = True
End If
End If
End Sub