Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: disable check box based on other checkbox
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Feb 2003
    Posts
    392
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default disable check box based on other checkbox

    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?

  2. #2
    MrExcel MVP
    Moderator
    xenou's Avatar
    Join Date
    Mar 2007
    Location
    Clev. OH, USA
    Posts
    16,474
    Post Thanks / Like
    Mentioned
    11 Post(s)
    Tagged
    1 Thread(s)

    Default Re: disable check box based on other checkbox

    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 by xenou; Jul 30th, 2019 at 04:47 PM.

    Using: Office 2010/Win7 (work) Office 2010/Win7 (home)

    You are rich in proportion to the number of things you can let alone.
    -- Henry David Thoreau

  3. #3
    Board Regular
    Join Date
    Feb 2006
    Location
    NJ, USA
    Posts
    354
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: disable check box based on other checkbox

    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
    - Posting guidelines, forum rules and terms of use

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes

    Also, when asking questions, please be as detailed as possible, and If I have helped you, please let me know.
    I don't require thanks, but acknowledgement is nice

  4. #4
    Board Regular
    Join Date
    May 2013
    Posts
    653
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: disable check box based on other checkbox

    +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

    Quote Originally Posted by Richard U View Post
    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
    Office 2007
    Access novice. Sometimes trying to give something back

  5. #5
    Board Regular
    Join Date
    Feb 2006
    Location
    NJ, USA
    Posts
    354
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: disable check box based on other checkbox

    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?
    - Posting guidelines, forum rules and terms of use

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes

    Also, when asking questions, please be as detailed as possible, and If I have helped you, please let me know.
    I don't require thanks, but acknowledgement is nice

  6. #6
    MrExcel MVP
    Moderator
    xenou's Avatar
    Join Date
    Mar 2007
    Location
    Clev. OH, USA
    Posts
    16,474
    Post Thanks / Like
    Mentioned
    11 Post(s)
    Tagged
    1 Thread(s)

    Default Re: disable check box based on other checkbox

    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 by xenou; Jul 31st, 2019 at 09:23 AM.

    Using: Office 2010/Win7 (work) Office 2010/Win7 (home)

    You are rich in proportion to the number of things you can let alone.
    -- Henry David Thoreau

  7. #7
    Board Regular
    Join Date
    May 2013
    Posts
    653
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: disable check box based on other checkbox

    Quote Originally Posted by Richard U View Post
    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?
    Office 2007
    Access novice. Sometimes trying to give something back

  8. #8
    MrExcel MVP
    Moderator
    xenou's Avatar
    Join Date
    Mar 2007
    Location
    Clev. OH, USA
    Posts
    16,474
    Post Thanks / Like
    Mentioned
    11 Post(s)
    Tagged
    1 Thread(s)

    Default Re: disable check box based on other checkbox

    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 by xenou; Jul 31st, 2019 at 11:59 AM.

    Using: Office 2010/Win7 (work) Office 2010/Win7 (home)

    You are rich in proportion to the number of things you can let alone.
    -- Henry David Thoreau

  9. #9
    Board Regular
    Join Date
    May 2013
    Posts
    653
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: disable check box based on other checkbox

    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.?
    Office 2007
    Access novice. Sometimes trying to give something back

  10. #10
    Board Regular
    Join Date
    Feb 2006
    Location
    NJ, USA
    Posts
    354
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: disable check box based on other checkbox

    Yes, if a selection should preclude others, radio buttons are the way to go.
    - Posting guidelines, forum rules and terms of use

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes

    Also, when asking questions, please be as detailed as possible, and If I have helped you, please let me know.
    I don't require thanks, but acknowledgement is nice

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •