Toggle checkboxes

G

Guest

Hello,

Not sure if this is possible or even a good idea, but here it is: I have a
yes/no field that I would like to control 2 check boxes [ok, I suppose it
would be more accurate to say that I want the check boxes to toggle the value
in the field]. When I check box 1, the field needs to be "true", and when I
check box 2, it needs to be false.

Thanks.
 
G

Guest

A checkbox's value is -1 when checked, 0 when unchecked.

For a checkbox's After Update event you could:

If chkBoxName1 = -1 Then
chkBoxName2 = 0
Else
chkBoxName2 = -1

Probably a way to write this using the "Not" operand, but there's the
simplest logic.
 
G

Guest

You don't need to use any code at all. Create an option group with two
options. Use check boxes rather than the usual radio buttons for each and
set the OptionValue property of the first to -1 and the second to 0. Set the
ControlSource of the option group to your Boolean (Yes/No) field.

BTW if you do use code its considered better programming practice to use the
Boolean constants TRUE and FALSE rather than their implementation as -1 or 0.
With the OptionValue property in the properties sheet you have to use -1 and
0 however, and accept the fact that you are being 'unduly chummy with the
implementation' as someone once put it.

Ken Sheridan
Stafford, England
 
G

Guest

I made an option group, that seemed to be the easiest way.
Thank you.

Ken Sheridan said:
You don't need to use any code at all. Create an option group with two
options. Use check boxes rather than the usual radio buttons for each and
set the OptionValue property of the first to -1 and the second to 0. Set the
ControlSource of the option group to your Boolean (Yes/No) field.

BTW if you do use code its considered better programming practice to use the
Boolean constants TRUE and FALSE rather than their implementation as -1 or 0.
With the OptionValue property in the properties sheet you have to use -1 and
0 however, and accept the fact that you are being 'unduly chummy with the
implementation' as someone once put it.

Ken Sheridan
Stafford, England

Niniel said:
Hello,

Not sure if this is possible or even a good idea, but here it is: I have a
yes/no field that I would like to control 2 check boxes [ok, I suppose it
would be more accurate to say that I want the check boxes to toggle the value
in the field]. When I check box 1, the field needs to be "true", and when I
check box 2, it needs to be false.

Thanks.
 

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

Similar Threads

Change button caption on each click 4
Select All Check Boxes Help 4
Toggle yes/no between table fields 1
Access 2010 0
simplest way...? 13
Auto Date for check boxes 13
Loop through checkboxes 7
Toggle forms 1

Top