Conditional IIF question/null value

K

Kerry

Hi! I've got a combo list in a form which I have the choices of multiple
numbers and an ALL choice (21, 22, 23, 24, ALL). I'm trying to use an IIF
statement in a query to either pull in the selected number to a criteria or
leave the criteria blank in the case of ALL so all data ends up in the report.

IIF([Forms]![FRM_000_GET_MARKET]![Combo13]=ALL,"",[Forms]![FRM_000_GET_MARKET]![Combo13])

So, THAT doesn't work ;) What's the best way for me to get it? THANKS in
advance for help!
 
A

Allen Browne

Switch your query to SQL View (View menu.)
Locate the WHERE clause.
Change it to look like this:
WHERE IIf([Forms]![FRM_000_GET_MARKET]![Combo13]='ALL', True,
[YourFieldNameHere] = [Forms]![FRM_000_GET_MARKET]![Combo13])

Explanation:
You can't just drop this into the Criteria row in query design, because the
criterion would then be applied against a particular field. The expression
above is designed to return TRUE if the combo contains 'All'. True is true
for all records, and so all records meet this WHERE condition. If the combo
value is not 'All', then the field is compared against the combo, so only
the matching records are returned.
 
K

Kerry

Awesome, thanks for the insight!

WHERE
(((IIf([Forms]![FRM_000_GET_MARKET]![Combo13]='ALL',True,([TBL_0100_SMS_COMPARE].[MER_DEPT_NBR])=[Forms]![FRM_000_GET_MARKET]![Combo13]))<>False));

Allen Browne said:
Switch your query to SQL View (View menu.)
Locate the WHERE clause.
Change it to look like this:
WHERE IIf([Forms]![FRM_000_GET_MARKET]![Combo13]='ALL', True,
[YourFieldNameHere] = [Forms]![FRM_000_GET_MARKET]![Combo13])

Explanation:
You can't just drop this into the Criteria row in query design, because the
criterion would then be applied against a particular field. The expression
above is designed to return TRUE if the combo contains 'All'. True is true
for all records, and so all records meet this WHERE condition. If the combo
value is not 'All', then the field is compared against the combo, so only
the matching records are returned.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Kerry said:
Hi! I've got a combo list in a form which I have the choices of multiple
numbers and an ALL choice (21, 22, 23, 24, ALL). I'm trying to use an IIF
statement in a query to either pull in the selected number to a criteria
or
leave the criteria blank in the case of ALL so all data ends up in the
report.

IIF([Forms]![FRM_000_GET_MARKET]![Combo13]=ALL,"",[Forms]![FRM_000_GET_MARKET]![Combo13])

So, THAT doesn't work ;) What's the best way for me to get it? THANKS in
advance for help!
 

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