iif, or, else?

J

jcarson

I am new to Access (trying to teach myself) and I'm having a syntax problem
with the below statement.

IIf([P]="Z","LAST",IIf([P]="U","LAST",IIf([MT]=0,"Delete",IIf([DF]<>0,"Delete","OK"))))

What I am trying to say is if value of [p] is Z or U return Last, if
[mt]=0 return delete, if [df] does not equal 0 return delete, else return OK.
I thought a nested iif would get the job done but i think i'm missing
something.
 
D

Douglas J. Steele

What's the symptom of your "syntax problem"? Are you getting an error
message? If so, what is it?
 
G

George Atkins

I presume this condition appears in a calculated field? I created a sample
database and ran your query in Acc2007 without any problem.

My table is (1st row contains field names):
P MT DF
z 0 1
u 1 1
x 0 1
z 1 1
r 1 0

I copied your formula into a blank Field header of a query based on this
table. I did not put it into the criteria row (which perhaps you did?), which
would not do what you want. Here is my calculated query field -
Answer:
IIf([P]="Z","LAST",IIf([P]="U","LAST",IIf([MT]=0,"Delete",IIf([DF]<>0,"Delete","OK"))))

The "Answer:" bit is just a de-facto name given to the returned column,
which returned the following results:

Answer
LAST
LAST
Delete
LAST
OK

George
 
G

George Atkins

Just a note: My reply shows the conditional field as if it is entered on two
lines. it is not. I forgot to add some spacing in the example, and it wrapped
to the next line. Sorry!

George
 

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