I am trying to check for duplicate address records in a table before running an append query to add the user-entered address on a form. I am defining a string to capture the street number, name, suffix and city and then using DLookup to search the table (tblLocation). The problem is that the code keeps returning a data type mismatch in criteria expression error. I know it has to do with the street number field because the code works fine when it is omitted. The street number field type is Number with a field size of Double. is there a way to format or convert the string so it will be accepted?
Code:
Private Function DupLocation() As Boolean
Dim strWhere As String
DupLocation = False
If IsNull(Me!txtStreetNumber) _
Or IsNull(Me!txtStreetName) _
Or IsNull(Me!txtSuffix) _
Or IsNull(Me!txtCity) Then Exit Function
strWhere = "(([Street]='" & Me!txtStreetName & "') AND " & _
"([Suffix]='" & Me!txtSuffix & "') AND " & _
"([City]='" & Me!txtCity & "') AND " & _
"([Number]='" & Me!txtStreetNumber & "'))"
If Not IsNull(DLookup("[Street]", _
"[tblLocation]", _
strWhere)) Then
DupLocation = True
Call MsgBox("This location already exists in the database." & vbCrLf & "Please select it from the 'Trespass Location' dropdown", vbExclamation, "Duplicate Location")
Else
Call MsgBox("This is a new location", vbInformation, "New Location")
Comment