+ Reply to Thread
Results 1 to 4 of 4

enable disable user form option button group

Hybrid View

  1. #1
    Registered User
    Join Date
    09-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    78

    enable disable user form option button group

    I have some user form of option buttons that share the same groupname "optGroup". I would like to enable/disable all option button ins "optGroup" by toggling a checkbox. So far, no working code, but rudimentary idea is:

    Private Sub Checkbox_Click()
    optGroup.Enabled = chkDays.Value
    End Sub
    This doesn't work because optGroup is not a object. So I was wondering is it possible to and how would I reference the the `Enabled` property of each option button in optGroup?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: enable disable user form option button group

    You could put the option buttons in a frame and then disable/enable the frame, and the option buttons.
    Private Sub CheckBox1_Click()
        Frame1.Enabled = CheckBox1.Value
    End Sub
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    09-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    78

    Re: enable disable user form option button group

    I did not realize i could do that, I will use this

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: enable disable user form option button group

    This doesn't work because optGroup is not a object.
    But you can treat it like one.
    Put this in the user forms code module.
    The button will toggle the enabled status of all the option buttons whose group name is "xx"

    Private Sub CommandButton1_Click()
        EnableOptionGroup("xx") = Not (EnableOptionGroup("xx"))
    End Sub
    
    Property Get EnableOptionGroup(Name As String) As Boolean
        Dim oneControl As MSForms.Control
        For Each oneControl In Me.Controls
            If TypeName(oneControl) = "OptionButton" Then
                If oneControl.GroupName = Name Then
                    EnableOptionGroup = oneControl.Enabled
                    Exit Property
                End If
            End If
        Next oneControl
    End Property
    Property Let EnableOptionGroup(Name As String, EnableValue As Boolean)
        Dim oneControl As MSForms.Control
        For Each oneControl In Me.Controls
            If TypeName(oneControl) = "OptionButton" Then
                If oneControl.GroupName = Name Then
                    oneControl.Enabled = EnableValue
                End If
            End If
        Next oneControl
    End Property
    You can also use code like

    EnableOptionGroup("xx") = False
    
    MsgBox EnableOptionGroup("xx")
    
    If EnableOptionGroup("xx") Then
        ' code
    End If
    If no option button has the .GroupName "xx" then EnableOptionGroup("xx") will return False. and setting the value of EnableOptionGroup("xx") will have no effect.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. enable/disable a command button in User Form w/ condition
    By Bidyut Chakraborty in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-02-2014, 03:11 AM
  2. [SOLVED] Disable option button on user form??????
    By Bflare in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-27-2014, 04:42 PM
  3. How I do disable and enable web browser control in access form on button click
    By krjoshi in forum Access Programming / VBA / Macros
    Replies: 0
    Last Post: 10-10-2013, 02:58 PM
  4. [SOLVED]VBA - Button(Form Control)-Disable/Enable->Alternate Solution
    By mcmunoz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-20-2013, 02:56 AM
  5. How to Enable/Disable the Option Button(s) based on different ComboBox Values?
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-30-2011, 04:32 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1