1

I keep getting a syntax error using Microsoft Access. I believe I am putting in the iif statement incorrectly. I am even using the expression builder. However, it keeps saying that there may be a misplaced comma enter image description here Please help

Respectfully,

1
  • 3
    Hi welcome to SO. You should post the code rather than linking an image. Commented Dec 22, 2019 at 20:45

2 Answers 2

1

In Design View instead of , use ; in the IIF() function:

IIf([LastName]="Smith";1;0)

If you see the query in SQL View though, you will see the function with commas.
This is a case applying to regions where the comma could be a decimal separator (check your regional settings of your PC).

Sign up to request clarification or add additional context in comments.

4 Comments

Expr1: IIf([lastname]="Smith";1;0) .... it still saying synatx error. checked regional settings and they are fine.
There is nothing wrong with your regional settings. You get an error because the , is not allowed in Design View. Switch to SQL View and write SELECT orders.SubTotal, IIf([LastName]="Smith",1,0) AS Expr1 FROM orders;. Then switch back to Design View and check the content of Expr1.
That Worked!! How would I get it to work in Design View?
When you switch back to design view from sql view, what is the expression?
0

The error is not due to the use of the comma in place of a semi-colon, but rather because you have set the Table row to Orders within the query grid:

enter image description here

As such, the query is attempting to access a field called [iif([LastName]="Smith",1,0)] from the table Orders, and this is an invalid field name.

Since you are using a calculated field which isn't being sourced directly from any particular table, clear Orders from the table row for this field to fix the error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.