I've got a UserForm with a Multipage added. One the first page, I have a single checkbox that I added programmatically. I can use its event _Click() to do something when it is clicked. Here is my code:
'*********************************
Option Explicit
Dim WithEvents myCB As MSForms.CheckBox
Private Sub myCB_Click()
MsgBox "I've been clicked"
End Sub
Private Sub UserForm_Initialize()
Dim i
i = 2
Set myCB = MultiPage1.Pages(0).Controls.Add("Forms.Checkbox.1", "chkbox" & i)
With myCB
.Top = (i - 1) * 20
.Left = 2
.Caption = "checkBox id# = " & i
End With
End Sub
'*********************************
This works just fine.
What I want to do is have myCB as an array. When I try this, I can't keep the _Click() functionality. Here is my code:
'*********************************
Option Explicit
Dim WithEvents myCB As MSForms.CheckBox
Private Sub myCB_Click()
MsgBox "I've been clicked"
End Sub
Private Sub UserForm_Initialize()
Dim i
i = 2
ReDim myCB(2 To 5)
For i = 2 To 5
Set myCB(i) = MultiPage1.Pages(0).Controls.Add("Forms.Checkbox.1", "chkbox" & i)
With myCB(i)
.Top = (i - 1) * 20
.Left = 2
.Caption = "checkBox id# = " & i
End With
Next i
End Sub
'*********************************
Can anyone send me in the right direction as to how I can make myCB an array and still keep my _Click() functionality??
Bookmarks