这是我已经多次工作的代码,修复了一个错误代码3061,然后是另一个,现在这个。任何想法为什么这个错误正在发生,所有对象拼写正确?
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 & "'*" & "));"
答案 0 :(得分:1)
检查Like运算符附近的语法。星号在单引号之外。尝试按如下方式替换它:
strSQL = "SELECT tblCustomer.IDCustomer, tblCustomer.PHONE, tblCustomer.LASTNAME, " & _
"tblCustomer.FIRSTNAME, tblCustomer.NAME, tblCustomer.EMAIL " & _
"FROM tblCustomer " & _
"WHERE (((tblCustomer.PHONE) Like " & "'*" & strForms & "*'" & "));"
在构建这样的动态SQL语句时,我喜欢做的事情是使用以下语句将其打印到调试窗口:
debug.print strSQL
更容易发现如下声明:
Like *'my_entered_value'*