这是我的 Microsoft Access 代码。我尝试在子表单中搜索某个关键字。我收到以下错误:运行时错误 3142。在 SQL 语句结束后发现字符。当我调试时,以下行会突出显示:Me.subMain_db.Form.RecordSource = SQL
。有人能告诉我如何修复此问题吗?谢谢!:)
Option Compare Database
Option Explicit
Private Sub btnSearch_Click()
Dim SQL As String
SQL = "SELECT main_db.creator_id, main_db.cw_id, main_db.supplier FROM main_db; WHERE creator_id LIKE ' * " & Me.txtKeywords & " * ' "
Me.subMain_db.Form.RecordSource = SQL
Me.subMain_db.Form.Requery
End Sub
答案1
Option Compare Database
Option Explicit
Private Sub btnSearch_Click()
Dim SQL As String
SQL = "SELECT main_db.creator_id, main_db.cw_id, main_db.supplier FROM main_db; WHERE creator_id LIKE ' * " & Me.txtKeywords & " * ' "
Me.subMain_db.Form.RecordSource = SQL
Me.subMain_db.Form.Requery
End Sub
删除此行中的分号:
SQL = "SELECT main_db.creator_id, main_db.cw_id, main_db.supplier FROM main_db; WHERE creator_id LIKE ' * " & Me.txtKeywords & " * ' "
分号是行终止符,表示“SQL 语句的结束”。
最后声明:
SQL = "SELECT main_db.creator_id, main_db.cw_id, main_db.supplier FROM main_db WHERE creator_id LIKE ' * " & Me.txtKeywords & " * ' "