runtime error 3075

angeljtm

New member
Local time
Today, 09:59
Joined
Apr 29, 2008
Messages
4
Hi! I am using the following code to search a form form a pop up form.

Private Sub cmdSearch_Click()

If Len(cboSearchField & vbNullString) > 0 Then
strCriteria = "[" & cboSearchField.Value & "] LIKE '*" & txtSearchString & "*' And "
End If

If Len(cboSearchField1 & vbNullString) > 0 Then
strCriteria = strCriteria & "[" & cboSearchField1.Value & "] LIKE '*" & txtSearchString1 & "*' And "
End If

If Len(strCriteria) > 0 Then
strCriteria = " Where " & Left$(strCriteria, Len(strCriteria) - 5)
End If

DoCmd.Close acForm, "frmSearch"
Form_frmServiceForm.RecordSource = "select * from [Service Table] " & strCriteria
MsgBox "Results have been filtered."


End Sub



Then using this code to open a report based off of the results.

DoCmd.OpenReport "Daily Service report", acViewPreview, , strCriteria

But I am getting an error that says "runtime error 3075
syntax error (missing operator) in query expression '(where [region] LIKE '*south*')." This is when I am searching the form for records containing the region as being south.

Any ideas on how to fix this??

Thanks!
 
remove the following code:
Code:
If Len(strCriteria) > 0 Then
strCriteria = " Where " & Left$(strCriteria, Len(strCriteria) - 5)
End If

you do not need the 'where'.

HTH,
Chris
 
Please put:
Debug.Print strCriteria

before the DoCmd.Close line in your code.

Copy the exact results from the immediate window back here without adding quotes, punctuation, or extra characters to set it off.

My concern is with the single quote in the error above before the "(where". That shouldn't be there. I'm also not sure where the "(" is coming from.
 
This is what occurs in the immediate window for debug.print strCriteria.

Where [Region] LIKE '*north*'
& Left$(strCriteria, Len(strCriteria) - 5)
 
Read Chris' post above. You do not need the last if statement.

Looks like you have an issue with the "AND" portion of your criteria too. You'll need to address this with additional logic.
 

Users who are viewing this thread

Back
Top Bottom