Type Mismatch Error.

gsrajan

Registered User.
Local time
Today, 07:01
Joined
Apr 22, 2014
Messages
227
I am getting type mismatch error for the following syntax. Kindly let me know what I am missing. When I remove the and City Like "" * " & Text49 & " * """ there is no error message. Thanks.

Dim dbs As Database
Dim rst As Recordset
Dim myString As String

On Error GoTo errorhandler

Set dbs = CurrentDb()
myString = "SELECT * FROM Masterqry WHERE Zip ='" & txtZipSearch & "' and soc_code='" & CboSOC & "' and City Like "" * " & Text49 & " * """

Set rst = dbs.OpenRecordset(myString)
If rst.RecordCount < 1 Then
MsgBox "No record found"
Cancel = True
Exit Sub
End If
Me.RecordSource = myString

Me.Refresh
Exit Sub
errorhandler:
Cancel = True
End Sub
 
You lost track of double and single quotes.

Check your bolded text and use single quotes appropriately.
 
Not sure if the spaces will make a difference ' * versus '* but I would get rid of those
Like '*" & Text49 & "*'"
 
Not sure if the spaces will make a difference
It would require the city record to have at least a leading and trailing space to be selected.

@gsrajan, Add the line below to your code to check exactly what sql string you are generating
Code:
debug.print myString
 

Users who are viewing this thread

Back
Top Bottom