IIF Statement error

I have an IIF statement that I am trying to use in a report.  I keep getting the error of "Syntax error (comma) in query expression".

Here is my statement:

Ch_Numb: IIF([At_Code]='32' OR [At_Code]'='38', 'FE5954',IIF([At_Code]='33','FE5946',[Ch_Numb],IIF([At_Code]= Null or "",[Ch_Numb])

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.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I believe you had an extra single quote just after the second [At_Code]:

Ch_Numb: IIF([At_Code]='32' OR [At_Code]='38', 'FE5954',IIF([At_Code]='33','FE5946',[Ch_Numb],IIF([At_Code]= Null or "",[Ch_Numb])
Richard DanekeTrainerCommented:
I agree about the extra ' that follows the second [At_Code], but there is more.
Let's examine: Ch_Numb: IIF([At_Code]='32' OR [At_Code]'='38', 'FE5954',IIF([At_Code]='33','FE5946',[Ch_Numb],IIF([At_Code]= Null or "",[Ch_Numb])  in parts:

Ch_Numb: <= names variable
IIF([At_Code]='32' OR [At_Code]'='38',  <= establishes IIF function and an OR test
 'FE5954',  <= value if true
IIF([At_Code]='33',  <= establishes IIF function for when false
'FE5946', <= value if true for At_Code = 33
[Ch_Numb]  <= value if false -- this should end the second IIF, but it continues...
,IIF([At_Code]= Null or "",[Ch_Numb])  <= so what and where does this belong?

I need a little more on intent before I can recommend a fix.
Dale FyeCommented:
I believe you have a number of issues with this statement.

1.  You have an extra [Ch_Numb] inserted in the statement (see highlighted text)
2.  You have 4 parameters for the 2nd IIF, not 3.
3.  You used improper syntax inside the last IIF to test for NULL or ""
4.  You only have 2 arguments inside the last IIF statement.  I've modified it as I think it should look (adding indentations to make it easier to read and debug.

IIF([At_Code]='32' OR [At_Code]'='38',
           IIF(NZ([At_Code], "") = "",

You might also consider using the Switch() function.  The Switch function takes pairs of information, the first item in each pair must evaluate to either True or False, the 2nd value in each pair is the value that will be returned if the first argument in the pair evaluates to True.  The function will continue to test pairs of data and return the first value that evaluates to true, which is why I like to add a final pair to my Switch functions.

I've also taken advantage of the IN (  ) clause to assess your first two potential values, and the NZ ( ) function for your last test.

Ch_Numb: SWITCH([At_Code] IN('32', '38'), 'FE5954', [At_Code]='33','FE5946', NZ([At_Code], "") = "", [Ch_Numb], true, 'Unknown')

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
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.

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.