Syntax error

L

Little Penny

I'm trying to adapt the following code to filter a user form, but I
keep getting the following error:

Any help would be greatly appreciated.

Runtime error 3075

Syntax error (missing operator) in query expression 'Media Type LIKE
'*P*"

Code:

Private Sub cmdSearch_Click()


If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
MsgBox "You must select a field to search."

ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True
Then
MsgBox "You must enter a search string."

Else

'Generate search criteria
GCriteria = cboSearchField.Value & " LIKE '*" &
txtSearchString & "*'"

'Filter frmCustomers based on search criteria
Form_frmMonthEndlb.RecordSource = "select * from Reprint
Request where " & GCriteria
Form_frmMonthEndlb.Caption = "Reprint Request (" &
cboSearchField.Value & " contains '*" & txtSearchString & "*')"

'Close frmSearch
DoCmd.Close acForm, "frmSearch"

MsgBox "Results have been filtered."

End If

End Sub
 
J

Jeanette Cunningham

Hi Little Penny,
try it like this:

GCriteria = cboSearchField.Value & " LIKE ""*" & txtSearchString & "*"""


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
L

Little Penny

Thanks for your reply Jeanette.

I made the changes you suggested. However the code is stopping for a
syntax error here:

Form_frmMonthEndlb.RecordSource = "select * from Reprint Request where
" & GCriteria
 
K

Ken Snell \(MVP\)

Change that line to this:

Forms!frmMonthEndlb.RecordSource = "select * from Reprint Request where " &
GCriteria
 
L

Little Penny

Changes were not successful. Maybe I should start from over. Can
anyone point me toward a tutorial for this?
 
K

Ken Snell \(MVP\)

Sorry, left out [ ] characters, assuming that "Reprint Request" is the name
of the table or query:

Forms!frmMonthEndlb.RecordSource = "select * from [Reprint Request] where "
& GCriteria
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top