[x]CheckBox1 [CommandButton1]
[x]CheckBox2 [CommandButton2]
[x]CheckBox3 [CommandButton3]
[x]CheckBox4 [CommandButton4]
'=== UserForm module ===
' Buttons is a Control-Array variable for CommandButton1-4.
Private WithEvents Buttons As clsBpca
' CheckBtns is a Control-Array variable for CheckBox1-4.
Private WithEvents CheckBtns As clsBpca
Private Sub UserForm_Initialize()
Dim j As Integer
Set Buttons = New clsBpca
Set CheckBtns = New clsBpca
'Initialize as CommandButton(Enabled=False) & CheckBox(Value=False)
'Link to CommandButton by Tag property of CheckBox.
For j = 1 To 4
Me.Controls("CommandButton" & j).Enabled = False
Me.Controls("CheckBox" & j).Value = False
Me.Controls("CheckBox" & j).Tag = "CommandButton" & j
'Add control to Control-Array.
Buttons.Add Me.Controls("CommandButton" & j)
CheckBtns.Add Me.Controls("CheckBox" & j)
Next j
'Generate Control-Array (with Click event)
Buttons.Rgst BPCA_Click
CheckBtns.Rgst BPCA_Click
End Sub
Private Sub UserForm_Terminate()
Buttons.Clear
CheckBtns.Clear
Set Buttons = Nothing
Set CheckBtns = Nothing
End Sub
'=== You can program Control-Array in the same way as VB6 in clsBpca. ===
'Any processing when you clicked CommandButton1-4.
Private Sub Buttons_Click(ByVal Index As Integer)
MsgBox Buttons(Index).Name & " is Clicked"
End Sub
'Any processing when you clicked CheckBox1-4.
Private Sub CheckBtns_Click(ByVal Index As Integer)
'Change Enable/Disable of CommandButton by CheckBox.
With CheckBtns(Index)
Me.Controls(.Tag).Enabled = .Value
End With
End Sub