I found this code on the microsoft support site. I tried to use it with my own tables. So I changed the names of the reports and the tables they were refering to in a clean manner. This code is the code of an action button which takes the values from three comboboxes and filters the data shown on a report.
When I try to use these filters, I get the correct values on the drop down list but when I push the go button, Access tells me I'm missing an operator, so I believe there's a syntax error somewhere.
Apparently, this code stores the value chosen in my filters. Could someone explain to me quickly these code lines???
Private Sub Command28_Click()
Dim strSQL As String, intCounter As Integer
'Build SQL String
For intCounter = 1 To 3
If Me("Filter" & intCounter) <> "" Then
strSQL = strSQL & "[" & Me("Filter" & intCounter).Tag & "] " & " = " & Chr(34) & Me("Filter" & intCounter) & Chr(34) & " And "
If strSQL <> "" Then
'Strip Last " And "
strSQL = left(strSQL, (Len(strSQL) - 3))
'Set the Filter property
Reports![rptCustomers].Filter = strSQL
Reports![rptCustomers].FilterOn = True
Reports![rptCustomers].FilterOn = False
From looking at the code i can see that when removing the last And the count is 3. " AND " is actually 5 characters.
Try sending the sql string to the screen (msgbox strSQL) after the string has been created, look for anything that looks incorrect. If you use debug.print strSQL in the code you can copy and past the sql created onto this forum.