Enabling and Disabling Check Boxes

JackD

Registered User.
Local time
Today, 23:01
Joined
Sep 11, 2008
Messages
20
Hi,

I have a form with several check boxes on it. I would like all the check boxes to be enabled for each new record, until the user selects just 1 of these check boxes, and when they do, the other checkboxes become disabled. Unless they click their selection for a second time, effectively clearing the tick and opening up all 5 options again.

A section of my form looks like

Which area do you live in or are nearest to?

Location1 [checkbox1]
Location2 [checkbox2]
Location3 [checkbox3]
Location4 [checkbox4]
Location5 [checkbox5]

I appreciate that this would be easier with a combo box listing the choices, however I am trying to mimic the look of a multiple choice survey on the form for some continuity for the data entry and also for easier verifying that the paper questionnaire has been entered correctly.

I have had a few attempts and the closest I seemed to have got is

Private Sub CheckBox1_AfterUpdate()
If CheckBox = -1 Then
Checkbox2.Enabled = False
Checkbox3.Enabled = False
Checkbox4.Enabled = False
Checkbox5.Enabled = False


Else
Checkbox2.Enabled = True
Checkbox3.Enabled = True
Checkbox4.Enabled = True
Checkbox5.Enabled = True
End If
End Sub


I applied the same after update event to each check box, chaging out which boxes I wanted enabled or disabled accordingly. This seemed to work until I moved to a new record, the checkboxes would still be greyed out apart from the 1 checkbox which was active from the previous record.


Any advice would be greatly appreciated!


Thanks in advance
 
I think you need like code in the form OnCurrent event.
 
Have you tried an option group? They will only allow one choice.
 
Paul's suggestion is really the way to go, I think. If all other checkboxes were disabled, how would the user correct a mistake they'd made? And like he said, only one box can be checked.

If you moved your code to the Form_Current event, you could correct a mistake when the record is originally entered, but the user could also make multiple selections, which you don't want!
 
I doubt we'll ever know because the poster has all of 1 post to his credit but the way I read this is that he has 6 check boxes. When the first one is checked it disables the other 5. If the first one is already checked and he unchecks it the the other 5 are enabled. Where is there anything about the second 5 check boxes being mutually exclusive? The only thing that is unclear to me is how he wants to handle a check box in the second 5 if one or more is checked and he dis-ables them by un-checking the first one? Does he want them cleared at that point?
 
Hi,

thanks for your suggestions, I do not have access to my dbase here but when I get a chance tomorrow I will try them out.

As a pure novice I'll take on as much as I can with your tips and will try to learn from your problem solving viewpoints and wisdom.

Kenhigg has pretty much fathomed out what I didn't explain particularly well.

The user has 5 checkbox options to choose from. To prevent the users from selecting more than one, as soon as they check one box the other 4 are disabled. If they uncheck their selection, the other 4 are enabled again allowing them to select another option if they selected the first one in error.

My probem occurrs when I move to a new blank record. All the check boxes start disabled, except the one check box that was selected on the previous record. If I check and uncheck this box in the new record, then all the checkboxes become enabled and I can continue as I had planned. This glitch is just not what I expected and it's annoying me quite a bit.

I will take alook at this Option group as Pbaldy suggests and also the different event areas missinglinq proffers. Is it possible to have an on-click event on a check box disable other checkboxes on the form? Plenty there for me to play around with and contemplate at work tomorrow.

Again, many thanks for your replies.
 
A note first: this may just be a typo, but your posted code

Private Sub CheckBox1_AfterUpdate()
If CheckBox = -1 Then

should be

Private Sub CheckBox1_AfterUpdate()
If CheckBox1 = -1 Then

When moving to a new record you need to set all checkboxes to Enabled. You can do this in the OnCurrent event Ken mentioned before. Something like

Code:
Private Sub Form_Current()
If Me.NewRecord Then
 Checkbox1.Enabled = True
 Checkbox2.Enabled = True
 Checkbox3.Enabled = True
 Checkbox4.Enabled = True
 Checkbox5.Enabled = True
End If
End Sub
 
Last edited:
Hi,

I tried a couple of suggestions and finally got a result I was looking for!

I just had a macro run on the on click event of each of the check boxes and instead of disabling / enabling them, i had the macro set the value for every other check box back to zero (other than the one the user was clicking of course). This stopped the user from ever being able to click any more than 1 option at a time.

Thanks for everyones input, it gave me other avenues to think about and helped me towards a solution that I am happy with.
 
This stopped the user from ever being able to click any more than 1 option at a time.
I'm glad you got something working, but you realize, of course, that this is exactly what Option Groups were invented to do. And it would have only taken about 2 minutes to have implemented.
 
I'm glad you got something working, but you realize, of course, that this is exactly what Option Groups were invented to do. And it would have only taken about 2 minutes to have implemented.

2 minutes is an understatement, however, it sounds like he is trying to control input... good luck! I found this very useful to disable and set an option box btw.:cool:
 

Users who are viewing this thread

Back
Top Bottom