disable check box based on other checkbox

deb

Active Member
Joined
Feb 1, 2003
Messages
400
Access 365
Within my main form f_pac,
I have 3 check boxes (USA, Canada, Combined)

I need to have them enabled/disabled.

If either USA or Canada is checked then disable Combined.
and
if Combined is checked disable USA and Canada.

How can I do this?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Simplest would be to use a radio button group - then only one can be "on" as a rule.

--(assuming that when you say either USA or Canada you don't mean that both USA and Canada can be checked .. which is obviously what Combined is).

So just google about MSAccess radio buttons.

Otherwise I guess you start digging into the checkbox to write code on their events (such as a check event or click event, if they have one, or otherwise on an update event). The job would be to craft the IF statements to handle all the cases - each checkbox, with two possibilities of checked or unchecked, so six cases to write for). But, anyway, this is what radio buttons are for so I'd go with the radio button approach.
 
Last edited:
Upvote 0
I suggest the radio buttons in a group as well, but here's the code if you can't use radio buttons for some reason

Code:
Private Sub Chk_Both_Click()
    Me.chk_usa.Value = False
    Me.Chk_Canada.Value = False
End Sub

Private Sub Chk_Canada_Click()
    Me.Chk_Both.Value = False
    Me.chk_usa.Value = False
End Sub

Private Sub chk_usa_Click()
    Me.Chk_Both.Value = False
    Me.Chk_Canada.Value = False
End Sub
 
Upvote 0
+1 for radio button as well.
Post was about enable/disable?, though clearing out the values as well would be a good idea?
Look at Me.ControlName.Enabled = True and Me.ControlName.Enabled = False

I suggest the radio buttons in a group as well, but here's the code if you can't use radio buttons for some reason

Code:
Private Sub Chk_Both_Click()
    Me.chk_usa.Value = False
    Me.Chk_Canada.Value = False
End Sub

Private Sub Chk_Canada_Click()
    Me.Chk_Both.Value = False
    Me.chk_usa.Value = False
End Sub

Private Sub chk_usa_Click()
    Me.Chk_Both.Value = False
    Me.Chk_Canada.Value = False
End Sub
 
Upvote 0
Look at Me.ControlName.Enabled = True and Me.ControlName.Enabled = False

If you use the Enabled, then how would you enable once you've set something to enabled = false?
 
Upvote 0
I know I should just test this myself but will the click work both when the checkboxes are checked (on) and unchecked (off). So we'd probably want to use the click event and also check that the box being "clicked" is checked (on). Otherwise, assume we are unchecking and do nothing.

Note that kinda agree that disable/enable is not really going to work well here - end result would be that once a choice is made it cannot be changed which assumes no mistakes ever (ah, if only...). Also still gotta say it ... radio buttons!
 
Last edited:
Upvote 0
If you use the Enabled, then how would you enable once you've set something to enabled = false?

By the change in state of whatever drives the condition to enable/disable ?
If combined is checked, disable USA & Canada
If combined is unchecked enable USA & Canada
If either of USA or Canada are checked, disable Combined
If both USA & Canada are unchecked enable Combined.

Clearing out the values as you suggested might help in not getting into a deadly embrace.?

Radio buttons would be still the best way?
 
Upvote 0
By the change in state of whatever drives the condition to enable/disable ?

well, strictly speaking the problem is that what's driving the condition can include things that were disabled (so can longer drive anything).

i.e,
... if you click Combined and that disables USA and Canada, you're stuck.
...if you click USA and that disables Combined, you're stuck (you can still change to Canada but not Combined)
...if you click Canada and that disables Combined, you're stuck (you can still change to USA but not Combined)

The problem is not that it doesn't work but that it isn't very friendly if someone checks the wrong box by mistake.

Still gotta go with radio buttons lol.


Note: You *could* have *two* checkboxes and just allow them to both be checked for combined (so no need of a special combined checkbox). That would be more appropriate for checkboxes. Checkboxes are for multiple selection (zero, one or more of a list of choices), while radio buttons are for single selection (only zero or one of a list of choices)
 
Last edited:
Upvote 0
Yes, not user friendly at all I agree, but my thoughts were, you untick and that enables again.
I think we all agree, radio buttons are the way to go, but it is up to the o/p at the end of the day.?
 
Upvote 0
Yes, if a selection should preclude others, radio buttons are the way to go.
 
Upvote 0

Forum statistics

Threads
1,213,513
Messages
6,114,072
Members
448,546
Latest member
KH Consulting

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top