A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Conditional IIF question/null value



 
 
Thread Tools Display Modes
  #1  
Old July 10th, 2008, 04:50 AM posted to microsoft.public.access.queries
Kerry
external usenet poster
 
Posts: 132
Default Conditional IIF question/null value

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!
  #2  
Old July 10th, 2008, 05:03 AM posted to microsoft.public.access.queries
Allen Browne
external usenet poster
 
Posts: 11,706
Default Conditional IIF question/null value

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
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Kerry" wrote in message
...
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!


  #3  
Old July 10th, 2008, 05:42 AM posted to microsoft.public.access.queries
Kerry
external usenet poster
 
Posts: 132
Default Conditional IIF question/null value

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" wrote:

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
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Kerry" wrote in message
...
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!



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:12 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.