This is an area that I strugle with
How do wite this query so that the syntax is correct.
GCriteria = Forms![frmRequest]![RequestName] & " = " &
Forms![frmSearchRequest]![txtSearchString1] "AND" & _
Forms![frmRequest]![RequestGroup] & " = " &
Forms![frmSearchRequest]![txtSearchString2] "AND" & _
Forms![frmRequest]![RequestColor] & " = " &
Forms![frmSearchRequest]![txtSearchString3]
I have trouble with using the carrage return
Also is the syntax different if I use LIKE
Thanks
Little Penny
Since we don't know anything about the structure of your tables, your
fieldnames, the meanings or datatypes of the fields, or the values in the form
controls, it's more than a bit difficult to say; but the criteria need to end
up being a valid SQL WHERE clause without the word WHERE. You can build a
query in the query grid showing an example of what you want to see. This would
include *the names of fields in your table* - unless your textbox RequestName
contains the name of a table field, this query of yours will NOT work.
Another problem is that you're not leaving spaces. The word AND is going to be
jammed against your fieldname - your criterion will end up something like
RequestName = JonesANDRequestGroup = SomeGroupANDRequestColor = Blue
Thirdly, if you are passing criteria to search Text fields the criterion must
be delimited by quotemarks - either " or (especially if the search term might
include apostrophes) ". A singlequote can be included in a string literal just
like any other character, but to include a doublequote you must use TWO
doublequotes.
So guessing that your table fields are RequestName, RequestGroup and
RequestColor, and that these are all Text (not lookup!) fields, a better
criterion construction might be
GCriteria = "[RequestName] = """ &
Forms![frmSearchRequest]![txtSearchString1] & _
""" AND [RequestGroup] = """ & _
Forms![frmSearchRequest]![txtSearchString2] & _
""" AND [RequestColor] = """ & _
Forms![frmSearchRequest]![txtSearchString3] & """"
This will construct a string like
[RequestName] = "Jones" AND [RequestGroup] = "SomeGroup" AND [RequestColor] =
"Blue"
If you'll explain what you want to do with LIKE - what kind of field you'll be
searching and what kind of wildcards you need - we can help with that.