W. McDowell
W. McDowell

Reputation: 9

Run-time error '3075': syntax error in query expression

I am creating a form on Access to filter a Subform based on the Column name "Control Type".

I am using a listbox to choose multiple values to filter with.

I also have a button that will execute the filter to the form.

I wrote this code:

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

I am getting a Run=time error '3075' for the line:

Task = "select * from tblAB where Control_Type = '" & strSearch & "' "

Upvotes: 1

Views: 1972

Answers (1)

LS_ᴅᴇᴠ
LS_ᴅᴇᴠ

Reputation: 11151

Run time error must not be on refered line.

From documentation:

The Filter property is a string expression consisting of a WHERE clause without the WHERE keyword.

So is not a complete SELECT sentence, but just:

Task = "Control_Type = '" & strSearch & "'"

Upvotes: 3

Related Questions