I have the following code that allow me to have dynamic checkboxes in an userform.
Private Sub UserForm_Activate()
Dim theCheckBox_ID(1 To 10) As MSForms.CheckBox
Dim CheckBoxTop As Integer
CheckBoxTop = 75
Dim i As Integer
For i = 1 To 10
Set theCheckBox_ID(i) = Controls.Add("Forms.CheckBox.1")
With theCheckBox_ID(i)
.Name = "chk_" & i
.Value = False
.Caption = ""
.Top = CheckBoxTop
.Left = 12
End With
CheckBoxTop = CheckBoxTop + 30
Next
Me.Height = CheckBoxTop + 100
End Sub
In such UserForm I have also a ComandButton; I would like to have specific MsgBoxes for each selected Checkboxes when I click on it.
The following code doesn't work as expected.
Private Sub cmd_SAVE_Click()
Dim j As Integer
For j = 1 To 10
If theCheckBox_ID(i).Value = True Then
MsgBox (theCheckBox_ID(i).Name)
End If
Next
End Sub
What's wrong???
Bookmarks