Consulting

Results 1 to 14 of 14

Thread: Sleeper: Enable Option Button only if more than 2 checkboxes are checked

  1. #1
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location

    Sleeper: Enable Option Button only if more than 2 checkboxes are checked

    Is there a way I can have it enable a particular option button on a user form if the User checks more than one checkbox. And then if he unchecks it down to one he it will disable?

  2. #2
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    I see from another thread how I can set the option button to disable but how do I set an if more than one checkbox in a collection?

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Put this code in the procedure

    Dim ctl As Control
    Dim cCBs As Long
    For Each ctl In Me.Controls
            If TypeName(ctl) = "CheckBox" Then
                If ctl.Value Then
                    cCBs = cCBs + 1
                End If
            End If
        Next ctl
    OptionButton1.Enabled = cCBs > 1
    and call the procedure from all checkbox click routines.

  4. #4
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Where do I put the name of the option box? Where it says me should I put the name of the collection? Also would this disable the Option box again if the number of checks go down to 1?

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    OptionButton1.

    No, that refers to the userform container.

    Yes.

  6. #6
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
     
    Sub EnableOption()
    Dim ctl As Control
    Dim cCBs As Long
    For Each ctl In DataView.Controls
        If TypeName(ctl) = "CheckBox" Then
            If ctl.Value Then
                cCBs = cCBs + 1
            End If
        End If
    Next ctl
    Column.Enabled = cCBs > 1
    End Sub
    It keeps telling me object required on the line:

    For Each ctl In DataView.Controls
    I tried the using the frame name (Dataview) and also the group name under properties for the checkboxes.

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What is DataView? You said you were suing a Userform, so use Me.

  8. #8
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Whenever I use Me it says invalid use of me command

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    So is it really a userform?

  10. #10
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Maybe I am using the wrong terminology. I created a custom form in VBA.

  11. #11
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You did Insert>Userform in the VBIDE?

  12. #12
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    Yes

  13. #13
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Can you post the workbook?

  14. #14
    VBAX Master
    Joined
    Jun 2006
    Posts
    1,091
    Location
    ok

Posting Permissions

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