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. |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|