Access IIf statement help


I'm having problem with the last part of my formula IIf([Column1]>[Column 2],[Column 2]))).    When I run the query, Column 1 is returning instead of Column 2, can you please assist?

IIf([Column 1]<"0","0",IIf([Column 1]<[Column 2],[Column1],IIf([Column1]>[Column 2],[Column 2])))
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
IIf([Column1]<"0","0",  IIf([Column 1]<[Column 2],[Column1],[Column 2]))

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
and watch out on the spaces   'Column1' vs 'Column 2' your names have spaces or not?


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
Dale FyeOwner, Developing Solutions LLCCommented:
You might want to replace the nested IIF() statements with a Switch statement

Switch([Column 1] < "0", "", [Column 1] < [Column 2], [Column 1], True, [Column 2])

But what if either of those columns is NULL, you might want to try:

Switch(Val(NZ([Column 1], 0)) < 0, 0, NZ(Column 1], 0) < NZ([Column 2], 0), [Column 1], True, [Column 2])

In your formula, you don't have anything that takes care of the situation where Column1 = Column2.  Both Jim and Dale gave you solutions that corrects that.  

In case you aren't aware though, I do want to point out that it looks like you're comparing string values and not numeric types.  So that may be a possible reason on why you think it's not working correctly.

Take a look at this sample of how the 2 data types behave differently:
Column1     Column2     Column1<Column2
  "11"        "3"           TRUE
   11          3            FALSE

Open in new window

Ron G.
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 Access

From novice to tech pro — start learning today.