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!

[b]IIf function in MS Access[/b]

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

 
Valeriya
Keep in mind that an IIf expression evalutes the true part and the false part. In other words...
IIf([Boy's name] = "Abner", "This is Abner", "not Abner")

In answer to your first question...
Although you can get results with nested IIf expressions, it is better to stay away from them, by using the Switch function or some other approach.

In answer to your second question...
Yes, there can be two conditions. In other words
IIf([Boy's name] = "Abner" AND [Hair] = "red", "This is Abner", "whatever")

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top