query variables

W

Wuffles

As a test I am trying to use variables in a table query. In the query design
criteria numeric field if I place >10 the query filters OK, but if I put a
variable in the criteria the query asks me in a box for a value for that
variable and if I type >10 it does not work.

What I am actually trying to do is define the criteria using variables from
a form through a forms!xxxx!variable entry in the criteria of the table
query. Variable = "10" works but variable= ">10" does not.

Please help if you can. Thank you.
 
P

Piet Linden

As a test I am trying to use variables in a table query. In the query design
criteria numeric field if I place >10 the query filters OK, but if I put a
variable in the criteria the query asks me in a box for a value for that
variable and if I type >10 it does not work.

What I am actually trying to do is define the criteria using variables from
a form through a forms!xxxx!variable entry in the criteria of the table
query.  Variable = "10" works but  variable= ">10" does not.

Please help if you can.  Thank you.

Makes sense... 10 is a number... >10 is a STRING. Big difference.

you cannot specify operators in the query criteria the way you are
attempting to. If you want to filter result sets on the fly, you have
two options (maybe more... but I can only think of two at the
moment)...
1. modify the query's SQL statement on the fly and saving it, then
opening the query.
2. create a report based on the unfiltered query, build the filter in
your unbound form (referencing whatever controls you wish), and
passing that filter in the open event of the report.
 
J

John W. Vinson

What I am actually trying to do is define the criteria using variables from
a form through a forms!xxxx!variable entry in the criteria of the table
query. Variable = "10" works but variable= ">10" does not.

You can pass *values* in a parameter - but you cannot pass *operators* such as
or BETWEEN or LIKE. If you need to allow users that flexibility, you'll need
two (or more) controls - perhaps a combo box offering the operators
< <= = >= >, and a textbox for the value. You'll need VBA code to actually
construct the SQL of the query.
 

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