0
votes

This is the code that I have worked over many many times, fix one error code3061, then another, now this. ANY IDEAS WHY THIS ERROR IS HAPPENING, all objects spelled correctly?

Dim strSQL As String
Dim strForms As String
strForms = [Forms]![frmEnterResRecordset]![txtPhone]

MsgBox strForms

strSQL = "SELECT tblCustomer.IDCustomer, tblCustomer.PHONE, tblCustomer.LASTNAME, " & _
       "tblCustomer.FIRSTNAME, tblCustomer.NAME, tblCustomer.EMAIL " & _
       "FROM tblCustomer " & _
       "WHERE (((tblCustomer.PHONE) Like " & "*'" & strForms & "'*" & "));"
1

1 Answers

1
votes

Check your syntax near the Like operator. The asterisks are outside the single quotes. Try replacing it as follows:

strSQL = "SELECT tblCustomer.IDCustomer, tblCustomer.PHONE, tblCustomer.LASTNAME, " & _
   "tblCustomer.FIRSTNAME, tblCustomer.NAME, tblCustomer.EMAIL " & _
   "FROM tblCustomer " & _
   "WHERE (((tblCustomer.PHONE) Like " & "'*" & strForms & "*'" & "));"

Something I like to do when building dynamic SQL statements like this is to print it to the debug window with the following statement:

debug.print strSQL

It's easier to spot statements like:

Like *'my_entered_value'*