Recoding Yes/No Data Type in a Query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to recode "Yes" to equal 1 and "No" to equal 0, but the data type
for this variable is Yes/No in the checkbox format and i get an error when I
type this command: OwnCar: IIf([P1T15OC]="Yes",1,IIf([P1T15OC]="No",0,-999))
in the query. Any ideas why this is happening and what I can do to fix it?

Thanks so much!
 
It's not "Yes" or "No". It's Yes or No. It's not text in a Boolean Yes/No
field.

If you want to do it much simpler, try this:

OwnCar: ABS([P1T15OC])

No is already 0 and Yes is -1. The ABS (absolute value) function flips it to
a 1.
 
I'm trying to recode "Yes" to equal 1 and "No" to equal 0, but the data type
for this variable is Yes/No in the checkbox format and i get an error when I
type this command: OwnCar: IIf([P1T15OC]="Yes",1,IIf([P1T15OC]="No",0,-999))
in the query. Any ideas why this is happening and what I can do to fix it?

Thanks so much!

The value of a bound Yes/No datatype field is a number, either -1 or
0, or True or False, or Yes or No, NOT a Text datatype "Yes".

OwnCar: IIf([P1T15OC]=Yes,1,IIf([P1T15OC]=No,0,-999))

Note: I would always use the actual number value instead of Yes or No.
OwnCar: IIf([P1T15OC]=-1,1,IIf([P1T15OC]= 0 ,0,-999))

However, as there are only the 2 choices (Yes or No) in a CheckBox
field, you would never see a -999.

I would not use an IIf statement at all.
You can shorten the entire line to:

OwnCar:Abs([PIT150C])

Your result will be a 1 or 0.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top