1
votes

I'm having issues with an onclick event for a checkbox in a vba form. Basically what I am trying to do is ammend the value of all checkboxes on specific tab to be the same value as a master checkbox. In this instance, it is the 'Use Online' captioned checkbox below (online_toggle in the code) which once clicked should toggle the other checkboxes on the tab 'on' or 'off'. I currently have the following code but it keeps producing an error at 'For Each obj In online.OLEObjects'

My user form

Private Sub online_toggle_Click()

Dim ctl As Control

For Each ctl In Me.MultiPage1.Pages(6).Controls

    If TypeOf ctl Is MSForms.CheckBox Then
        If ctl.GroupName = "online_variants" Then
        If ctl.Name <> "online_toggle" Then
            ctl.Value = online_toggle.Value
        End If
        End If
    End If

Next ctl

End Sub

N.B. online is the name of the tab on which all of the checkboxes are situated. If it helps the checkboxes affected by the master checkbox are all grouped as online_variants

Cheers,

Jason

1
Is that a Multipage that you are using OR A Tabstrip?Siddharth Rout
I think it's a tabstrip. If it helps, the checkboxes that need to be altered are grouped under the name online_variants.jezzipin
In that case I think it is a Multipage. In design time, in a Tabstrip the controls in Tab1 are visible in Tab2 as well whereas in the Multipage when you switch between tabs you can see independent controls...Siddharth Rout
In that case it is a multipage.jezzipin

1 Answers

1
votes

In a Mutipage the page numbering starts from 0 so if you are trying to refer to the Checkboxes in the Online tab (7th Tab) then use this

Dim ctl As Control

For Each ctl In Me.MultiPage1.Pages(6).Controls
    If TypeOf ctl Is MSForms.CheckBox Then
        '~~> Your code here
        Debug.Print ctl.Name
    End If
Next