IIF Statement in Access Query

This is what I had so far:
NewField: IIf([Field1]=True,[Field1],IIf([Field2]=True,[Field2],IIf([Field3]=True,[Field3],IIf([Field4]=True,[Field4])))))

The above query is not giving me the right answer.

I have a Access query with 5 fields and IIF statements based on the 4 fields(Field1, Field2, Field3, Field4) into Newfield.

Please see attach example in word document.

Thank you.
Queennie LAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

So if any of the 4 fields are True, you want the 5th field to be True too? In that case you can use:


Newfield : Field1 AND Field2 AND Field3 AND Field4
Dale FyeCommented:
Actually, I think you mean:

NewField = [Field1] OR [Field2] OR [Field3] OR [Field4]
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

If any member of the team has to be good to select the team, then use OR.
If each member of the team has to be good to select the team, then use AND.
That's why I love building coded function for this stuff.  Nested IIF's can be confusing/hard to read.

Function GetAnswer(byref field1 as Boolean, byref field2 as Boolean, byref field3 as Boolean, byref field4 as Boolean) as Boolean

if field1 = true then
     GetAnswer = field1
elseif field2 = true then
     GetAnswer = field2
elseif field3 = true then
     Getanswer = field3
elseif field4 = true then
     Getanswer = field4
end If
exit function

Now, use the function in your query:
YourAnswer= GetAnswer([field1],[field2],[field3],[field4])

Scott C
Queennie LAuthor Commented:
None of these give me what I needed.

If Field1, Field2, Field3, Field4 has "complete" then show it in Newfield else show Overdue, Assigned and if null then leave it blank.

I used the OR and AND.

Thank you.
As you see Overdue is just mentioned in in the last comment.
What does "has complete" mean?
An example with meaningful data would speed up the solution.
List variations of values and the required value of the IIF statement.
Leo AlexanderCommented:
If Field1, Field2, Field3, Field4 has "complete" then show it in Newfield else show Overdue, Assigned and if null then leave it blank.

If Field1 ="Complete" Then
  If Field2 = "Complete" Then
    If Field 3="Complete" Then
      If Field 4= "Complete" Then
         Newfield = "Complete/Whatever you want"

          Newfield = "Overdue"
          Exit Sub
End If
End If
End If
End If
Hi there,

If you are using an access  query and not VBA (in order to create Case of If statements) maybe you should look into using the switch function:

ex: Switch (SupplierID=1, "IBM", SupplierID=2, "HP", SupplierID=3, "Nvidia")

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Queennie LAuthor Commented:
Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.