I have a Excel VBA Userform with two frames (Frame1 and Frame2) that I populate with a lot of Checkboxes depending on the amount of data when the form loads:
The interested code is:
Private Sub enterNewTextbox(number As Long, nameAdd As String, side As String)
Dim boxTop As Long
Dim a As Long
Dim nameCB As String
Dim checkBox As Control
boxTop = 10 + (number * 18) - 18
nameCB = side & number & "CB"
If side = "Left" Then
Set checkBox = Frame1.Controls.Add("Forms.CheckBox.1", nameCB)
Else
Set checkBox = Frame2.Controls.Add("Forms.CheckBox.1", nameCB)
End If
With checkBox
.Value = False
.Top = boxTop
.Left = 12
.Width = 190
.Name = nameCB
.Caption = nameAdd
End With
End Sub
Now I would like to loop through all the controls again and get all the controls that was added to the left frame - something like this:
For Each ctrl In Me.Controls
If TypeName(ctrl) = "Checkbox" Then
If **{find the name of the frame that the Checkbox is in}** = "Frame1" Then
'Be awesome here
End If
End If
But when I look in the Properties of the control I don't find any field to query that shows me what frame it is in.