IIf statement with multiple Else conditions?


B

Bill C

Hello, I am attempting to make an If-Then type expression that will give me
multiple "Else" values. (doesnt have to be If-Then, any variation that will
work is fine)

For instance, I know this isn't correct language but I essentially need
something similar to this:

IIf(
![column]= "Var1", "Desired Result"
ElseIf (not sure if anything like this can be used)
![column] =
"Var2", "2nd Desired Result"
etc. etc.

Again, I know this isn't proper syntax for If-Then statements, just put that
way to get my intention across. I am comfortable working in the Design view.
Thanks a lot anyone who can help!!
 
Ad

Advertisements

B

Bill C

Phil,

That is perfect! I have never used the Switch function before but it looks
like that'll solve my headache.

Thanks a lot!!

PhilT via AccessMonster.com said:
Bill,

Why don't you use switch function which is more flexible than IIf Then. It
goes like this switch([fieldname]="var1","Desired Result",[filedname]="var2",
"Desired Result 2", etc....). However, I like to add True, "Others" at the
end for anything did not meet the condition. Make sure put True, "Others"
inside the bracket, and "Others" can be anything you want.

Bill said:
Hello, I am attempting to make an If-Then type expression that will give me
multiple "Else" values. (doesnt have to be If-Then, any variation that will
work is fine)

For instance, I know this isn't correct language but I essentially need
something similar to this:

IIf(
![column]= "Var1", "Desired Result"
ElseIf (not sure if anything like this can be used)
![column] =
"Var2", "2nd Desired Result"
etc. etc.

Again, I know this isn't proper syntax for If-Then statements, just put that
way to get my intention across. I am comfortable working in the Design view.
Thanks a lot anyone who can help!!
 
F

fredg

Hello, I am attempting to make an If-Then type expression that will give me
multiple "Else" values. (doesnt have to be If-Then, any variation that will
work is fine)

For instance, I know this isn't correct language but I essentially need
something similar to this:

IIf(
![column]= "Var1", "Desired Result"
ElseIf (not sure if anything like this can be used)
![column] =
"Var2", "2nd Desired Result"
etc. etc.

Again, I know this isn't proper syntax for If-Then statements, just put that
way to get my intention across. I am comfortable working in the Design view.
Thanks a lot anyone who can help!!



How many different choices?
Just a few? Let's say 3 different choices.
NewColumn:IIf([FieldName] = "Var1","Desired Text",IIf([FieldName]=
"Var2","DifferentText","DefaultText"))

You can also use Choose() if the [FieldName] returns a 1, 2, 3, etc.,
number value.
NewColumn:Choose([FieldName],"DesiredText if 1","DesiredText if
2","DesiredText if 3")

Or, as suggested by PhilT the Switch() function.

Also, you can create user defined function in a module using a Select
Case statement or an If..ElseIf..Else..EndIf in the function and refer
to that function in your query,
NewColumn:MyFunctionName([FieldName])
 
Ad

Advertisements

C

Colleen

Thank you so much for the help!
For a week or so now, I've been trying to create a date-based IIf statement
with three results. I was pretty sure an IIf statement would work - and I
really haven't had time to look at the Switch function and learn it.
The solution was, as I had hoped, simple enough using the following IIf
statement:
Active Calculated: IIf(Date()<[Begin Date this appt],"Pending",IIf(Date()
Between [Begin Date this appt] And [Expire Date this appt],"YES","NO"))
Cool - thanks so, so much!
-Colleen

PhilT via AccessMonster.com said:
Bill,

Why don't you use switch function which is more flexible than IIf Then. It
goes like this switch([fieldname]="var1","Desired Result",[filedname]="var2",
"Desired Result 2", etc....). However, I like to add True, "Others" at the
end for anything did not meet the condition. Make sure put True, "Others"
inside the bracket, and "Others" can be anything you want.

Bill said:
Hello, I am attempting to make an If-Then type expression that will give me
multiple "Else" values. (doesnt have to be If-Then, any variation that will
work is fine)

For instance, I know this isn't correct language but I essentially need
something similar to this:

IIf(
![column]= "Var1", "Desired Result"
ElseIf (not sure if anything like this can be used)
![column] =
"Var2", "2nd Desired Result"
etc. etc.

Again, I know this isn't proper syntax for If-Then statements, just put that
way to get my intention across. I am comfortable working in the Design view.
Thanks a lot anyone who can help!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top