If anyone could help me out, I'd greatly appreciate it.
I'm getting a data type mismatch in the following expression. I love what this code does but I've always had trouble getting it to work properly. Both LastName and FirstName table fields are formatted = Short Text.
Thanks!
Code:
' If on a new row,
If (Me.NewRecord = True) Then
' Check for similar name
If Not IsNothing(Me.LastName) Then
' Open a recordset to look for similar names
Set rst = CurrentDb.OpenRecordset("SELECT LastName, FirstName FROM " & _
"tblContacts WHERE Soundex([LastName]) = '" & _
Soundex(Me.LastName) & "'")
' If got some similar names, issue warning message
Do Until rst.EOF
strNames = strNames & rst!LastName & ", " & rst!FirstName & vbCrLf
rst.MoveNext
Loop
' Done with the recordset
rst.Close
Set rst = Nothing
' See if we got some similar names
If Len(strNames) > 0 Then
' Yup, issue warning
If vbNo = MsgBox("The System found contacts with similar " & _
"last names already saved in the database: " & vbCrLf & vbCrLf & _
strNames & vbCrLf & "Are you sure this contact is not a duplicate?", _
vbQuestion + vbYesNo + vbDefaultButton2, "Question?") Then
' Cancel the save
Cancel = True
End If
End If
End If
End If