Nested if using Switch

matthewR
5StarLounger
Posts: 627
Joined: 03 Feb 2010, 15:02

Nested if using Switch

Post by matthewR »

I am trying to use the following in a query. When I try to put the last statement in, I get and error saying: The expression you entered has an invalid string. A string can be up to 2048 characters long, including opening and closing quotation marks.
Is there any way to do this? I thought Switch instead of an IF statement but I am not sure how. I tested each statement and it works up until the last statement. I want it to go to null if none of the statements are true.

Rating Categories: NZ(Switch([Rep_District] In ("8","10","13","17","22","23","19") And [Rating1]="ASO/ASC" And [Control_Plan_Code]=80782855,"National ASO",

[Rep_District] In ("8","10","13","17","22","23","19") And ([Rating1]="Cost Plus" Or [Rating1]="Insured") And [control_Plan_Code]=80782855,"National Ins",

[ASM_District] In ("19","14") And [Rating1]="ASO/ASC" And [Control_Plan_Code]=80782887,"National Central ASO",

[ASM_District] In ("19","14") And ([Rating1]="Cost Plus" Or [Rating1]="Insured") And [Control_Plan_Code]=80782887,"National Central Ins",

[Rep_District] In ("1","2","3","4","5","7","9","20","21") And [Rating1]="ASO/ASC","Western Reg ASO",

[Rep_District] In ("1","2","3","4","5","7","9","20","21") And ([Rating1]="Cost Plus" Or [Rating1]="Insured"),"Western Reg Ins",

[ASM_District] In ("18","24","25","26","27","28","32") And [Rating1]="ASO/ASC","Central Reg ASO",

[ASM_District]in("18","24","25","26","27","28","32") and ([Rating1]="Cost Plus” or [Rating1]=”Insured”),”Central Reg Ins”))

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Nested if using Switch

Post by HansV »

In the last part

... ([Rating1]="Cost Plus” or [Rating1]=”Insured”),”Central Reg Ins”))

all quotes except the first one are "curly quotes" instead of "straight quotes". If you change the curly quotes to straight quotes, the expression should work OK:

... ([Rating1]="Cost Plus" or [Rating1]="Insured"),"Central Reg Ins"))
Best wishes,
Hans

matthewR
5StarLounger
Posts: 627
Joined: 03 Feb 2010, 15:02

Re: Nested if using Switch

Post by matthewR »

That worked. Thanks. I don't understand because I had the single quotes. I took the calculation into Word to edit and that is where the curly quotes got in. It works now and that is great.

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Nested if using Switch

Post by HansV »

Editing in Word can be handy, but by default, Word replaces straight quotes with smart quotes aka curly quotes, and those don't work in VBA and in expressions. For that reason, I usually turn this feature off in Word:
x79.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

matthewR
5StarLounger
Posts: 627
Joined: 03 Feb 2010, 15:02

Re: Nested if using Switch

Post by matthewR »

Thanks for the info.