Checkbox Question

B

BobV

Group:

I have a form with three checkboxes on it and an OK button. I want the user
to be able to select either one, two, or three checkboxes. Then when the OK
button is pressed, some code will be executed that will vary depending if
one, two or all three of the checkboxes have been checked. The checkboxes
are not in an Option Group on the form; they are simply on the form. I did
not put them in an Option Group because it only allows one box to be checked
at a time. I am using the code below to set a variable when a checkbox has
been clicked.

Private Sub FedCheckBox_Click()
ApplyFed=1
En Sub

Private Sub StateCheckBox_Click()
ApplyState=1
En Sub

Private Sub BookCheckBox_Click()
ApplyBook=1
En Sub

My question is how do I toggle the variable between 1 and 0 if the user
checks a box and then decides to uncheck the same box? Do I use a different
event to trap this situation? What event would that be. Or what code do I
need to have behind the above Click events to accomplish this?

Your help will be greatly appreciated.

Thanks,
BobV
 
D

Douglas J. Steele

There's really no need to set variables. FedCheckBox will have a value of -1
if it's been checked, or 0 if it's not checked. (and it'll be Null when it's
grayed-out because a value hasn't been set yet) You should simply be able to
refer to the control as

Abs(Nz(Me.FedCheckBox, 0))
 
B

BobV

Thank you so much Doug. I knew there had to be a better way to accomplish my
goal.

BobV
 

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