运行时错误'3075':查询表达式中的语法错误

问题描述 投票:1回答:1

我正在Access上创建一个表单,根据列名称“控件类型”过滤子表单。

我正在使用列表框来选择要过滤的多个值。

我还有一个按钮,可以对表单执行过滤器。

我写了这段代码:

Private Sub cmdSearch_Click()
Dim varItem As Variant
Dim strSearch As String
Dim Task As String

For Each varItem In Me!listControl.ItemsSelected
     strSearch = strSearch & "," & Me!listControl.ItemData(varItem)
Next varItem

If Len(strSearch) = 0 Then
     Task = "select * from tblAB"  
Else
     strSearch = Right(strSearch, Len(strSearch) - 1)
     Task = "select * from tblAB where Control_Type = '" & strSearch & "' "
End If
Me.tblAB_subform.Form.Filter = Task

Me.tblAB_subform.Form.FilterOn = True

End Sub

我得到一行Run = time错误'3075':

Task = "select * from tblAB where Control_Type = '" & strSearch & "' "
vba ms-access
1个回答
2
投票

运行时错误不得在引用行上。

来自documentation

Filter属性是一个字符串表达式,由不带WHERE关键字的WHERE子句组成。

所以不是一个完整的SELECT句子,但只是:

Task = "Control_Type = '" & strSearch & "'"
© www.soinside.com 2019 - 2024. All rights reserved.