Condition to test a YES/NO field?

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

Guest

How do I test a Yes/No field in a Macro?
If I type: [fieldname] = "Yes" in the condition field, I get a type
mismatch.
 
While they're named Yes/No fields, they actually hold True or False. Try
True (with no quotes), or -1 (False is 0)
 
That is what I thought. I've tried them all, and even tried changing the
field back to text. Somehow, what's wrong must be staring me in the face,
but I can't see it. (I've tried other text fields and it's worked)

Douglas J. Steele said:
While they're named Yes/No fields, they actually hold True or False. Try
True (with no quotes), or -1 (False is 0)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



C-squared said:
How do I test a Yes/No field in a Macro?
If I type: [fieldname] = "Yes" in the condition field, I get a type
mismatch.
 
Thank you. I tried them all - but must be something else is getting me. What
else would cause a "type mismatch"? c2

Steve Schapel said:
C²

All of these will do it:

[fieldname]=-1
[fieldname]=Yes
[fieldname]=True

--
Steve Schapel, Microsoft Access MVP

C-squared said:
How do I test a Yes/No field in a Macro?
If I type: [fieldname] = "Yes" in the condition field, I get a type
mismatch.
 
C²

You're absolutely sure [fieldname] it is a Yes/No data type?
What is the macro action that you are using this as a Condition for?
Maybe the 'type mismatch' is coming from somewhere else, not the
condition expression itself.
Other than that, sorry, I can't think where the problem may arise.
[fieldname]=Yes is definitely correct syntax for what you are trying to do.
 
Steve,

Thank you for your reply. I am sure it's a yes/no data type. The action I'm
aiming for a SetValue with [fieldname].[fontitalic] -1, and I can get it to
work with other conditions.

I made a seperate database and seperate report, I got it to work there - so
I'll keep playing with it.

C2

Steve Schapel said:
C²

You're absolutely sure [fieldname] it is a Yes/No data type?
What is the macro action that you are using this as a Condition for?
Maybe the 'type mismatch' is coming from somewhere else, not the
condition expression itself.
Other than that, sorry, I can't think where the problem may arise.
[fieldname]=Yes is definitely correct syntax for what you are trying to do.

--
Steve Schapel, Microsoft Access MVP

C-squared said:
Thank you. I tried them all - but must be something else is getting me. What
else would cause a "type mismatch"? c2
 
C²

Is fieldname represented on the form by a checkbox? Is the checkbox
also called fieldname? If so, it won't have a FontItalic property...
maybe that's the problem?
 
Steve,

Thank you. You hit the nail on the head. By a process of elimination, I had
just figured out the checkbox needs to be listed (even if not displayed) on
the detail line of the report in order to get it to work.

C2

Steve Schapel said:
C²

Is fieldname represented on the form by a checkbox? Is the checkbox
also called fieldname? If so, it won't have a FontItalic property...
maybe that's the problem?

--
Steve Schapel, Microsoft Access MVP

C-squared said:
Steve,

Thank you for your reply. I am sure it's a yes/no data type. The action I'm
aiming for a SetValue with [fieldname].[fontitalic] -1, and I can get it to
work with other conditions.

I made a seperate database and seperate report, I got it to work there - so
I'll keep playing with it.

C2
 
Steve,

P.S. I was not applying the FontItalic property to the checkbox (which I
didn't want displayed), but to another field.

C2

Steve Schapel said:
C²

Is fieldname represented on the form by a checkbox? Is the checkbox
also called fieldname? If so, it won't have a FontItalic property...
maybe that's the problem?

--
Steve Schapel, Microsoft Access MVP

C-squared said:
Steve,

Thank you for your reply. I am sure it's a yes/no data type. The action I'm
aiming for a SetValue with [fieldname].[fontitalic] -1, and I can get it to
work with other conditions.

I made a seperate database and seperate report, I got it to work there - so
I'll keep playing with it.

C2
 
C²

Just a hint for the future, then... In newsgroup discussions it is
often good to refer to your actual field and/or control names. In your
examples, you were using [fieldname] to refer to two different things,
which doesn't necessarily make things any easier :-)
 
Steve,

Thank you. Will do.

C2

Steve Schapel said:
C²

Just a hint for the future, then... In newsgroup discussions it is
often good to refer to your actual field and/or control names. In your
examples, you were using [fieldname] to refer to two different things,
which doesn't necessarily make things any easier :-)

--
Steve Schapel, Microsoft Access MVP


C-squared said:
Steve,

P.S. I was not applying the FontItalic property to the checkbox (which I
didn't want displayed), but to another field.

C2
 
Back
Top