Evaluating Multiple Conditions

deejay_totoro

Registered User.
Local time
Today, 13:21
Joined
May 29, 2003
Messages
169
Using IIf to get a result

Hello,

I would like to convert a numeric value into something more meaningful for my users.

I thought about using the IIf statement, but cant get it to work.

What I basically want is:

If question 1 = 5, then the answer is "good", If question 1 = 6, then the answer is "bad", If question 1 = not 5 or 6, then "no answer given."


It would be really great if someone cold helpe me with this.

Thank you!

dj_T
 
The syntax should be like this:
IIf([question1]=5,"good",IIf([question1]=6,"bad","no answer given"))
 
deejay

Sometimes conditional formating works for these situations too.

In forms design view
format>>Conditional formatting

Good luck
Tom
 
Hello,

Thanks for the replie.

I was able to get the rsults I wanted with the following:

myq1: IIf([question1]="1","poor",IIf([question1]="2","Beginner",IIf([question1]="3","Intermediate",IIf([question1]="4","Excellent","no answer given"))))

However what I was wondering is this:

If I leave the Table: line blank for the above, it works fine. However, if I try to add the name of the table here, it produces the following error.

Syntax error (comma) in query expression tbl.Test etc....

Whats happening here?

When I use multiple tables in the query - it doesnt seem to work. Do I need to define the table in the expression? What would the syntax be in this case?

Thanks very much!

dj_T
 
Last edited:
The syntax when you want to include table names is [tablename].[fieldname] as in:
IIf([tablename].[fieldname]="1",etc....

I would follow Pat's advice and use the Choose() or Switch() function instead since you've now got more than 3 alternatives. It's much more readable than the nested IIf() functions.

Another alternative is to create a table of your classifications that would look like this:
1 poor
2 beginner
etc....
just add the table to the query, join it based on classification number, and you can pull the classification description in.
 
syntax

Ah,

In this case, what is the syntax for using Choose() or Switch() functions?

thanks!

dj_T
 
Check out the Access online help - it's an invaluable resource!
 

Users who are viewing this thread

Back
Top Bottom