Quote:
Originally Posted by Barkol I already know how to basically use the iif statement in a query, checking for true of false. For instance: iif(x=1,"X equals 1","X does not equal 1")
How would I go about doing multiple options using the iif statement in a query. I don't know much about VBA, so I'd like to keep this in a query.
For example, if x equals the following, I would like this displayed:
x=1 ----- "Enter Customer Information"
x=2 ----- "Edit Customer Information"
x=3 ----- "Delete Customer Information"
x=4 ----- "Exit"
You're help would be greatly appreciated. Thanks!! |
Basically, you just substitute another Iif() for each "false", so that it says, in effect: If this is true, then this is the value, if not, then If THIS is true, then THIS is the value, if not, then If
THIS is true ... etc.
You have to be really careful with all the parentheses, and if you need more than a few conditions, it can get very hard to read or modify, not to mention running slow. Here's how your example should look:
Code:
Iif(x=1,"Enter Customer Information",
Iif(x=2,"Edit Customer Information",
Iif(x=3,"Delete Customer Information,
Iif(x=4,"Exit","ERROR!"))))
As a quick check, the number of closing parentheses at the end needs to be the same as the number of conditions, excluding the last or default.