Share via

IIF Statement in Access - Invalid String error message

Anonymous
2022-10-20T21:22:08+00:00

Hello - Can anyone help on why I'm getting this error message?

=IIf([dbo.PoPurchGroup].[code]="COSPAC", "Central Oil", IIf([dbo.PoPurchGroup].[code]="RELADYNE", "Central Oil", IIf([dbo.PoPurchGroup].[code]="COSBR", "Central Oil", IIf([dbo.PoPurchGroup].[code]="Robert Only", "Shell Bulk", IIf([dbo.PoPurchGroup].[code]="SHEBUL", "Shell Bulk", IIf([dbo.PoPurchGroup].[code]="SHEBUL-MS", "Shell Bulk-MS", IIf([dbo.PoPurchGroup].[code]="SHEPAC", "Shell Package", "OTHER”)))))))

I even tried just 1 statement and I get a " is invalid error.

I've followed the example:

=IIf([CountryRegion]="Italy", "Italian", IIf([CountryRegion]="France", "French", IIf([CountryRegion]="Germany", "German", "Some other language")))

Microsoft 365 and Office | Access | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2022-10-21T11:03:24+00:00

    I strongly endorse what Peter and Duane have said.  You are currently encoding data in an expression.  A fundamental principle of the database relational model is the Information Principle (Codd's Rule #1). This requires that all data be stored as values at column positions in rows in tables, and in no other way.

    By storing the data correctly in a table you simply need to join that table to your current table on the Code columns to return the appropriate value.

    Was this answer helpful?

    0 comments No comments
  2. Duane Hookom 26,825 Reputation points Volunteer Moderator
    2022-10-21T07:59:13+00:00

    I totally agree with Peter. Consider reading this blog post https://weblogs.sqlteam.com/jeffs/2006/02/10/9002/.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2022-10-21T07:14:32+00:00

    Put the data in a table (code, full name). In your solution you need to rebuild your application If a new value needs to be added.

    Was this answer helpful?

    0 comments No comments
  4. ScottGem 68,830 Reputation points Volunteer Moderator
    2022-10-20T23:23:39+00:00

    Are you sure you got the opening anc closing parentheses correct?

    You might try building the expression one nested IIF at a time.

    Or you might try using the SWITCH function: Switch Function (microsoft.com)

    Was this answer helpful?

    0 comments No comments