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

Format Of IIF Function in MS Access

Status
Not open for further replies.

Valeriya

MIS
Jan 9, 2006
138
US
Can IIf function have the following form:

IIf( *condition*, IIf(*condition*, *expression*, *expression))

I looked up every kind of explanation of IIf functions and all the sources say that IIf functions has to have the following form and every part of it is required:

IIf(*condition*, *expression*, *expression)

Well this one --- IIf( *condition*, IIf(*condition*, *expression*, *expression)) does not correspond to the above required form as the nested IIf statement evaluates to one expression, the second one is missing...So basically the above nested IIf statement has one condition and only one expression, yet it works just fine in one of the queries that I'm working on.

Can IIf statement have more then one condtion like :



IIf(*condition_1* and *condition_2*, *expression*, *expression*)



Thanks so much!



Valeriya

 
Yes an IIf statement can have more then one Condition

IIf(*condition_1* and *condition_2*, *expression*, *expression*)

The above expression is valid.

Regards
 
To further "HandsOnAccess"'s response:

YES you can combine multiple IIF statements... it's called "nesting" them.

Ex:

IIF([someField]="Some String","1st IF was TRUE", IIF([someOtherField]="Some Other String","2nd IF was TRUE", "Neither IF was TRUE"))

You can put the inner IF condition in the place of either the TRUE expression or the FALSE expression, OR BOTH - it doesn't matter.

Note you can nest and nest and nest these things but there is a limit (I don't remember what it is offhand). It's rare you'd ever hit a situation where you hit that limit though.

Just keep your brackets straight and you're all good.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top