issue with to many IIF statements in my DoCmd.RunSQL command

cirugio

Board Regular
Joined
Mar 30, 2010
Messages
130
Within my ACCESS database, I have some sql logic built within a function which utilizes the IIF statement. It was working fine until I had to expand it. Now I am receiving a Run-time error '3075': Expression too complex in query expression 'IIF(............. I am assuming there is to many IIF statements. Is there a way I can rewrite this? Especially, since this will continue to expand over time.

I would love to use case statements but I don't think it is allowed within access. Any help is greatly appreciated. Thanks for your time in advance.



Code I currently have in place:

DoCmd.RunSQL "UPDATE ALL_Midas_Data_FINAL as F " & _
"SET F.w_bank_name = IIf(F.bank = '0021','Italy', " & _
"IIf(F.bank = '0022','Ireland', " & _
"IIf(F.bank = '0154','Saudi', " & _
"IIf(F.bank = '0377','Germany', " & _
"IIf(F.bank = '0069','Paris', " & _
"IIf(F.bank = '0062','Chicago', " & _
"IIf(F.bank = '0349','Florida', " & _
"IIf(F.bank = '0088','Canada', " & _
"IIf(F.bank = '0089','India', " & _
"IIf(F.bank = '0028','Beijing', " & _
"IIf(F.bank = '0009','London', " & _
"IIf(F.bank = '0075','NTGS', " & _
"IIf(F.bank = '050x','Singapore', " & _
"IIf(F.bank = '050u','Singapore', " & _
"IIf(F.bank = '0079','Luxembourg', " & _
"IIF(F.bank = '0073','Scotland', " & _
"IIf(F.bank = '0023','Australia','??????')))))))))))))))));"
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
It looks like what you have is a straight lookup situation, so just create a lookup table, and link that table to it on your "bank" field.
Then all you have to do to expand is add more records to your lookup table (shouldn't have to change your code at all).
 
Upvote 0
Thank you! not sure why I did not think of that. I guess, I was just thinking about expanding what was already there. Your approach is much cleaner. Thanks again!!!!
 
Upvote 0

Forum statistics

Threads
1,221,875
Messages
6,162,563
Members
451,775
Latest member
Aiden Jenner

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top