iif and or not working in Access update query

DRANDON

Active Member
Joined
Jun 30, 2006
Messages
268
I am trying to get a "Y" or a "N" in an Access query (Flag).

Here is my "update to" formula:

IIf([ADMISSION SVS CD]="EOP" And [I/O]="O","Y","N") Or IIf([ADMISSION SVS CD]="EO2" And [I/O]="O","Y","N")

Inexplicably I get "-1" for all records as a result. What is wrong with it?

Thank you so much in advance.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
I figured it out.

IIf([ADMISSION SVS CD]="EOP" Or [ADMISSION SVS CD]="EO2" And [I/O]="O","Y","N")
 
Upvote 0
Try like this:
Code:
[COLOR=#333333]IIf((([ADMISSION SVS CD]="EOP" Or [ADMISSION SVS CD]="EO2") And [I/O]="O"),"Y","N")[/COLOR]
 
Upvote 0
I figured it out.

IIf([ADMISSION SVS CD]="EOP" Or [ADMISSION SVS CD]="EO2" And [I/O]="O","Y","N")
Though not necessary, I would recommend adding in at least a single pair of parentheses like this, for readability:
Code:
[COLOR=#333333]IIf([/COLOR][COLOR=#ff0000]([/COLOR][COLOR=#333333][ADMISSION SVS CD]="EOP" Or [ADMISSION SVS CD]="EO2"[/COLOR][COLOR=#ff0000])[/COLOR][COLOR=#333333] And [I/O]="O","Y","N")[/COLOR]
That just makes it more obvious to the reader to process the "Or" part first, and then the "And", instead of vice versa.
 
Upvote 0
Actually this worked perfectly,

IIf([ADMISSION SVS CD]="EOP" And [I/O]="O" Or [ADMISSION SVS CD]="EO2") And [I/O]="O","Y","N")
 
Upvote 0
Code:
[COLOR=#333333]IIf([ADMISSION SVS CD]="EOP" And [I/O]="O" Or [ADMISSION SVS CD]="EO2") And [I/O]="O","Y","N")[/COLOR]
That cannot work as written, it has unbalanced parentheses (only one left one and two right ones).

And why are you checking [I/O] twice for the same value? The second one after the AND is totally unnecessary.
 
Upvote 0
Though not necessary, I would recommend adding in at least a single pair of parentheses like this, for readability:
Code:
[COLOR=#333333]IIf([/COLOR][COLOR=#ff0000]([/COLOR][COLOR=#333333][ADMISSION SVS CD]="EOP" Or [ADMISSION SVS CD]="EO2"[/COLOR][COLOR=#ff0000])[/COLOR][COLOR=#333333] And [I/O]="O","Y","N")[/COLOR]
That just makes it more obvious to the reader to process the "Or" part first, and then the "And", instead of vice versa.

Yes, I see what you mean about readability, thank you. Turns out, I needed to put the And [I/O]="O" into the first section for accuracy. So it became:

IIf([ADMISSION SVS CD]="EOP" And [I/O]="O" Or [ADMISSION SVS CD]="EO2") And [I/O]="O","Y","N")
 
Upvote 0
Yes, I see what you mean about readability, thank you. Turns out, I needed to put the And [I/O]="O" into the first section for accuracy. So it became:

IIf([ADMISSION SVS CD]="EOP" And [I/O]="O" Or [ADMISSION SVS CD]="EO2") And [I/O]="O","Y","N")

I guess I'll just repeat what Joe said - the parentheses are unbalanced as posted (syntax problem), and the I/O = "O" check two times is redundant (doesn't improve accuracy).

It's actually hard to know what your intention is with the broken parentheses. Do both or only one of the [ADMISSION SVS CD] values need to go with the [I/O] = "O" check?
 
Upvote 0

Forum statistics

Threads
1,214,412
Messages
6,119,369
Members
448,888
Latest member
Arle8907

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