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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mathematical Comparison Operators in Combo Box and Query

Status
Not open for further replies.

kazaccess

MIS
Aug 8, 2013
4
US
I have a form that takes in combo box values and then runs a query based on those values. One combo box contains the mathematical comparison operators (<,>,=,etc.) and the other is a text box formatted to general number. I am currently unable to string these together in my WHERE condition (query editor, not VBA) and get a correct result. Currently, the query runs but seems to be disregarding my specifications. The code and variations of it that I have tried in my WHERE condition are : [Score] & [Forms]![MyFormName]![MathematicalOperator] & [Forms]![MyFormName]![TextBoxNumber]. I am using this to query my table to find values >,<,=,>=,<=,<> to the number in the text box. For example I would like to get values where Score > 3 Any ideas on how to string this together properly?
 
When you concatenate as you are you are building a string that contains what looks like a logical operator but there is not one.

A long shot would be that the following code works. I think Eval will not do the logical comparison (it will do arithmetic operations).

Code:
Eval([Score] & [Forms]![MyFormName]![MathematicalOperator] & [Forms]![MyFormName]![TextBoxNumber]) = Yes

Alternately, you could right your own function and use Select Case to branch the operator to get at your result... But this will be making a user defined function required for your criteria... a performance issue for sure.

The best bet is to dynamically build your SQL statement in code. That way the whole thing can be customized at once.
 
I guess technically you could use a complex where condition where you test the logical operator AND the test it represents.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top