View Full Version : Iif statement to define selection criteria.


askey
04-12-2002, 01:26 PM
I want to use an Iif to define selection criteria. The Iif statement check the value in a form and if it meet requirements uses the value as selection criteria in the query if it doesn't meet requirements it should select all records. I'm sure its a syntax problem but not sure. The Iif staement reads as follows.
IIf([Forms]![frm_set_query_values]![datGrade]>=0,[Forms]![frm_set_query_values]![datGrade],Like "*")

this returns the results when value in ([Forms]![frm_set_query_values]![datGrade]is > 0 but not all values when it is not. help

Travis
04-12-2002, 04:16 PM
Try this:

IIf(Nz([Forms]![frm_set_query_values]![datGrade],-1)>=0,[Forms]![frm_set_query_values]![datGrade],Like "*")

The problem may be that

[Forms]![frm_set_query_values]![datGrade]=Null

Pat Hartman
04-12-2002, 07:42 PM
You can't change the relational operator in a query using this method. The IIf() function as written will return an actual value such as 1 or the phrase Like*. That means the where statement will look like:
Where SomeField = 1;
or
Where SomeField = "Like *";
which is of course NOT what you want and should explain why the first part works but not the second.

Change the criteria to:

[Forms]![frm_set_query_values]![datGrade] OR [Forms]![frm_set_query_values]![datGrade] Is Null