Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query help with a drop down and a text box for criteria

Status
Not open for further replies.

mndiscer

Programmer
Sep 8, 2010
11
US
Hello, I'm trying to create a query where you can select the comparision and enter in the number to compare. So I have a drop down list with <,>,= and have a text box to capture the numeric value. In the query criteria I've tried
Forms!Form.DroplistV & Forms!form.NumV and
Forms!Form.DroplistV & " " & Forms!form.NumV and I've also tried creating a string on the form and pulling that string over
Forms!Form.StringV
But nothings working, I'd really like to not use VBA and keep it between the form and query.

Any insight would be helpful.

Thanks!
 

What you are looking for is the Eval() Function. Concatenate your expression into a string and then use Eval.

Code:
Dim x as String
Dim y as String
Dim z as String

x = "2"
y = "4"
z = ">"
Debug.Print Eval(x & z & y)

The result will be False (or 0). If you reverse the order (y & z & x) the result will be True (or -1). You should be able to get what you want if you play with it.
 
Sorry comparison was the wrong word. I have an employee report and I'm trying to create the criteria from a single dropdown and a text box. So if the user wants to see all records where the employee has greater than 8 hours, he would select the ">" and type in "8". or if he wants to see anyone with less than 4 hours he would select "<" and enter "4" hours. Sorry for the confusion.

 
You can't use a control on a form (or any type of parameter) to update the operator (=, Between, <, >, ...).

The solution I would suggest depends on if you are using the query as the Record Source of a form or report.

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top