Select Query Help

L

Little Penny

What is wrong with this slq statemnt. When I hit my cmd button in my
form i get a pop up box that says "Enter Paramater Value"


GCriteria = Forms![frmSearchFields]![cboSearchField].value & " = " &
Forms![frmSearchFields]![txtSearchString].value


Form_frmOriginal.RecordSource = "select * from tbl_ReprintRequest
Where " & GCriteria

I can get this to work with "LIKE"

GCriteria = Forms![frmSearchFields]![cboSearchField].value & " LIKE
'*" & Forms![frmSearchFields]![txtSearchString].value & "*'"



but Not "="


Any help would be greatly appreciated


Thanks





Little Penny
 
D

Duane Hookom

You probably need to add more quotes to handle text fields like:
GCriteria = Forms![frmSearchFields]![cboSearchField].value & " = """ &
Forms![frmSearchFields]![txtSearchString].value & """ "
 
J

John Spencer

Change this
GCriteria = Forms![frmSearchFields]![cboSearchField].value & " LIKE
'*" & Forms![frmSearchFields]![txtSearchString].value & "*'"

To this
GCriteria = Forms![frmSearchFields]![cboSearchField].value & " =
'" & Forms![frmSearchFields]![txtSearchString].value & "'"

Or to this
GCriteria = Forms![frmSearchFields]![cboSearchField].value & " LIKE
'" & Forms![frmSearchFields]![txtSearchString].value & "'"

Note the inclusion of the ' as a text delimiter. This assumes that your field
is going to be a text field. If Forms![frmSearchFields]![cboSearchField] can
return the name of a NUMBER or DATE field then you will need to test for the
data type and add # characters in place of the ' character for Dates. For
number fields you would need to remove the ' characters.


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 

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