468,283 Members | 1,673 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,283 developers. It's quick & easy.

How to dynamically assign a query field its criteria?

I have an A97 query (qryVehiclesNowners2) that has a table
field in it named [DateLeft]. Depending on the selections made
in a number of criteria choices on a form, a field on the form
will have string values in it like...

Between #12/1/2004# And #12/31/2004# - or -
= #6/10/2005# - or -

Between #6/1/2005# And #6/30/2005#

I want to use them as criteria for the query.

There's a combo-box on the form whose row-source is the
above named query, qryVehiclesNowners2. How do I tell the
query that the criteria for that field is sitting in
Forms!MyForm!MyCrit waiting to be read 'n used?

I tried this on the criteria row in the QBE grid...

But I get a message saying "This expression is typed incorrectly,
or it is too complex to be evaluated. For example, a numeric ex-
pression may contain too many complicated elements. Try
simplifying the expression by assigning parts of the expression
to variables." The query runs fine if I delete only that field or
simply remove the reference criteria.

So I deleted the criteria, created a global var to hold the criteria
string value and a procedure in a standard module to return the
global var's value when called. Then I put the following criteria
in the query's [DateLeft] field:
However, the query still pukes with the same error.

If I cut 'n paste the string from frmLookUpAvehicle's TimeCrit
textbox into the query, it runs as expected. So there's nothing
wrong with the syntax of the criteria string. Just seems it cannot
be referenced in the query - must be typed in there explicitly.

Someone know the answer?
Nov 13 '05 #1
0 1866

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Steve | last post: by
3 posts views Thread by John young | last post: by
22 posts views Thread by Stan | last post: by
5 posts views Thread by DeanL | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.