Condition to test a YES/NO field?

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.
 
S

Steve Schapel

C²

All of these will do it:

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

Douglas J. Steele

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

Guest

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.
 
G

Guest

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.
 
S

Steve Schapel

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.
 
G

Guest

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
 
S

Steve Schapel

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?
 
G

Guest

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
 
G

Guest

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
 
S

Steve Schapel

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 :)
 
G

Guest

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
 

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

Top