Where to type the IIF statement?

G

Guest

How do I use IIF to do the following...

I have a query with a column header (field) titled "SCORE"
The values or (records) for score are "HIGH" or "LOW"

I want to include the "SCORE" field or column and...
Add a new column that converts the HIGH or LOW to a numerical value of "3"
or "1"

I tried using the following expression:

IIF([SCORE]="HIGH",1,IIF([SCORE]="LOW",1," "))

However, I got errors. I really don't know where this expression should by
typed into....do I type it into the "Field" row or the "Criteria" row of the
query design view?

Thanks!
 
P

Pat Hartman

Type the expression in the Field row:

ScoreNum:IIF([SCORE]="HIGH",3,IIF([SCORE]="LOW",1,Null))
or if you want the value for not high and not low to be 2 --
ScoreNum:IIF([SCORE]="HIGH",3,IIF([SCORE]="LOW",1,2))

You had both high and low returning 1, so I changed high to return 3.
 
G

Guest

Pat,
Thanks for your suggestion, I think we're closer, but not quite there yet.

Access seemed to take the expression you suggested below. However, when I
returned to the query view (not the design view), each record under the new
column "ScoreNum" contained "#Error" in it.

Any ideas?





Pat Hartman said:
Type the expression in the Field row:

ScoreNum:IIF([SCORE]="HIGH",3,IIF([SCORE]="LOW",1,Null))
or if you want the value for not high and not low to be 2 --
ScoreNum:IIF([SCORE]="HIGH",3,IIF([SCORE]="LOW",1,2))

You had both high and low returning 1, so I changed high to return 3.

help me said:
How do I use IIF to do the following...

I have a query with a column header (field) titled "SCORE"
The values or (records) for score are "HIGH" or "LOW"

I want to include the "SCORE" field or column and...
Add a new column that converts the HIGH or LOW to a numerical value of "3"
or "1"

I tried using the following expression:

IIF([SCORE]="HIGH",1,IIF([SCORE]="LOW",1," "))

However, I got errors. I really don't know where this expression should by
typed into....do I type it into the "Field" row or the "Criteria" row of the
query design view?

Thanks!
 
S

Steve Schapel

Help Me,

I think the expressions which Pat suggested are valid, so I can't think
of a reason for it not working, unless you made a typo in the expression
when you entered it in query design.

Here's an alternative, which I would personally prefer...
ScoreNum:Switch([SCORE]="HIGH",3,[SCORE]="LOW",1)
 
G

Guest

OK...Thanks Steve, it seemed to work. However there's a new catch that I'm
trying to resolve.

The "expression" works only if the records in the orginal "Score"
column/field are "text" or "hand-typed". For example, someone actually typed
in "HIGH", "MEDIUM", or "LOW".

The expression does not work if the records in the "Score" column are picked
from a "pull-down" list or combo box. In this case, the result I get is a
bunch of empty boxes in the new field "ScoreNum".

So, it seems like the expression only recognizes hand-typed text, but not
combo box.

Any thoughts?

Steve Schapel said:
Help Me,

I think the expressions which Pat suggested are valid, so I can't think
of a reason for it not working, unless you made a typo in the expression
when you entered it in query design.

Here's an alternative, which I would personally prefer...
ScoreNum:Switch([SCORE]="HIGH",3,[SCORE]="LOW",1)

--
Steve Schapel, Microsoft Access MVP


help said:
Pat,
Thanks for your suggestion, I think we're closer, but not quite there yet.

Access seemed to take the expression you suggested below. However, when I
returned to the query view (not the design view), each record under the new
column "ScoreNum" contained "#Error" in it.

Any ideas?
 
S

Steve Schapel

Help Me,

It sounds like something odd about the combobox. Like it's a
multi-column combobox, with one column hidden, and it is the hidden
ciolumn which is the "bound column", so even though it appears that the
value being entered int he field is "HIGH" etc, this is not the actual
data being entered, it is the value of the hidden combobox column. This
sort of confusion sometimes arises as a result of using the Lookup
Wizard to create the field in table design.
 

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

Similar Threads

IIF Function 2
Grouping - Distinct 5
Nested Iif Formula Question 3
Counting in Query 3
How to update using a query? 1
IIF statement in query 3
Query IIF function 3
Iif Query 5

Top