Hopefully this will be a quick fill in the blank.
I'm wanting to loop through the first 13 Frames of a Userform and think the below code will do what I want, but I have been unable to figure out how to set cFrame.
Code:Dim Ctrl as Control Dim cFrame as Frame X = 1 to 13 cFrame = What goes here? For Each Ctrl in cFrame.Controls Doing stuff here. Next Ctrl Next X
Last edited by magness; 01-27-2010 at 01:40 PM.
something like this,
Order appears to be based on that of controls creationCode:Dim cltTemp As MSForms.Control Dim lngCount As Long For Each cltTemp In Me.Controls If TypeOf cltTemp Is MSForms.Frame Then lngCount = lngCount + 1 If lngCount > 13 Then Exit For Debug.Print cltTemp.Name, cltTemp.Caption, cltTemp.Controls.Count End If Next
hmm... Less than ideal since I'd have to rearrange all the frames (they weren't created in any specific order) They are however named sequentially. Is there a way to say something like cFrame = "Frame" & X?
Thank you though. If there isn't a way to do the above this will be very helpful.
If the controls all have the same name then
Code:Dim cFrame As MSForms.Frame Dim lngIndex As Long For lngIndex = 1 To 13 Set cFrame = Me.Controls("Frame" & lngIndex) Debug.Print cFrame.Name, cFrame.Caption, cFrame.Controls.Count Next
Thank you, this clears it up. Sorry I wasn't more specific in the initial post and mentioning they were named sequentially.
I had tried:
And it didn't work. But yours does. The only real difference I can see is using Set for cFrame. What is the difference between saying "cFrame =" and "Set cFrame ="?Code:Dim cFrame As MSForms.Frame For X = 1 To 2 cFrame = Me.Controls("Frame" & X) For Each Control In cFrame.Controls Debug.Print Control.Name Next Control Next X
You need to use the Set keyword in order to assign a reference to an object.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks