Get the names of subforms in a tab control (1 Viewer)

abenitez77

Registered User.
Local time
Today, 17:59
Joined
Apr 29, 2010
Messages
141
I have a main form that has a Tab Control. The tab control could have 5 to 10 tabs. Each tab has a subform and in some instances a tab could have a tab inside that tab with subforms as well. I want to be able to get the subform names in each tab.

I am able to get the main form name by using me.form.name

How can i get the names of each subform in each tab?

I am creating a dynamic form and need to get the names into variables for later use
 

jdraw

Super Moderator
Staff member
Local time
Today, 17:59
Joined
Jan 23, 2006
Messages
15,364
Are you sure these are subforms and not Pages? Typically a Tab control has "tabbed Pages".
 

stopher

AWF VIP
Local time
Today, 21:59
Joined
Feb 1, 2006
Messages
2,396
The following subroutine loops through all controls on a form and if it is a tab, lists all the subforms on the tab. For each subform it runs the subroutine again to do exactly the same check. It will go as deep as the level of sub forms you have.

Code:
Public Sub GetSubFormNames(myForm)
    'loop through all controls on main form
    For Each ctl In myForm.Controls
        
        If ctl.ControlType = 123 Then  ' this is a tab control so lets look at the pages
            
            'loop through each page on the tab control
            For Each currentpage In ctl.Pages
                
                'loop though each control on the current page
                For Each pageControl In currentpage.Controls
                
                    If pageControl.ControlType = 112 Then  'this is a subform so output the name
                        Debug.Print "Tab: "; currentpage.Name; "  Subform name: "; pageControl.Name
                        
                        'check for tab controls on the current subform
                        GetSubFormNames pageControl
                        
                    End If
                    
                Next pageControl
                
            Next currentpage
        End If

    Next ctl
End Sub

hth
 

Users who are viewing this thread

Top Bottom