How I can get access to the nested controls of a control?
I have serveral frames on my user interface and every frame contains serveral other controls (like labels, buttons, ...). I have to iterate over the frames and change content of the children of a specific frame (e.g. set another text in a label).
So far I iterate over all controls of my frame and I check if the control in the loop control variable is the frame where the changes should be.
Dim cntrl As Control
For Each cntrl In Controls
'Debug.Print cntrl.Name // here I get all controls on the form
If cntrl.Name = "Frame_Name" Then
If cntrl.Index = index Then
Debug.Print "true" ' here the caption of nested components should be changed
End If
End If
Next
Now I have the frame in the control variable but the problem is that I get no access to the nested label to change the label's caption. What can I do?
You need to look at the Container property of each control. The following code should give you the idea:
Dim cntrl As Control
For Each cntrl In Controls
If cntrl.Container.Name = "Frame_Name" Then
Debug.Print cntrl.Name & " is nested in the specified frame"
End If
Next