I am using this vba code to prevent double entry:
The code works well to prevent double entry, unfortunately, if the name I typed includes an APOSTROPHE (ex. John's Cafe), syntax error 3075 appears.
Do you have any suggestions to correct the error?
Code:
Private Sub BusinessName_AfterUpdate()
Dim NewBusinessName As String
Dim stlinkcriteria As String
NewBusinessName = Me.BusinessName.Value
stlinkcriteria = "[BusinessName] = " & "'" & NewBusinessName & "'"
If Me.BusinessName = DLookup("[BusinessName]", "Sheet1", stlinkcriteria) Then
MsgBox "" & NewBusinessName & " is already in the Database." _
& vbCr & vbCr & "Data Entry Denied!!!", vbInformation, "DUPLICATE ENTRY"
Me.Undo 'undo the process and clear all fields
Do you have any suggestions to correct the error?
Comment