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

IIF Function/Arguments

Status
Not open for further replies.

Bensta

Programmer
Joined
Jul 21, 2003
Messages
122
Location
US
I was wondering if there is another equivalent IIf function to evaluate more than 2 conditions right in a query
I know that the IIF can return only 2 values. I don't want to use a function to return more than 2 values upon evaluating my conditions.
This is t I am trying to achieve:
IIf(Codition1=1,"Stuff1",elseif condition=2,"Stuff2", else condition=3,"Stuff3") I assume there will be and else condition
I would greatly appreciate any help
Thank you
 
There's no ELSE explicitly in an IIF statement but you can get what you want with nested IIF's like this

IIf(Codition1=1,"Stuff1",IIF(condition=2,"Stuff2", "Stuff3"))

So that "Condition1=1", assigns "Stuff1" if its true and it evaluates the second IIF if "Condition1=1" is false.
 
Thank you so much. It worked perfectly.
Bensta
 
Watch out for the IIF "gotcha" when it's used in a query- it evaluates BOTH the True & False values/results, regardless of the condition. I've had some subtle problems with nulls & divide-by-Ø issues.

And, just to compound the confusion, the above ONLY applies to using IIF in a query/VBA statement. If you use it in a form or report, it checks EITHER the True or False result, not both.

It's enough to make Mother Teresa kick puppies.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top