In VBA, Identify the "Container" of a Given Control (1 Viewer)

whdyck

Registered User.
Local time
Today, 17:48
Joined
Aug 8, 2011
Messages
169
For any given control on a form, I need to know, in VBA, whether that control is on a tabpage, and if so, which one (Page Index is fine). Can this be done in VBA?

Thanks.

Wayne
 

MarkK

bit cruncher
Local time
Today, 15:48
Joined
Mar 17, 2004
Messages
8,186
Yes. Check the Parent property of the control. Code example...
Code:
Private Sub Command11_Click()
    Dim ct As Access.Control
    Dim pg As Access.Page
    
    For Each ct In Me.Controls
        If [COLOR="Blue"]TypeOf ct.Parent Is Access.Page[/COLOR] Then
[COLOR="Green"]            'this control is on a tab page[/COLOR]
            Set pg = ct.Parent
            Debug.Print ct.Name & " is on page " & pg.Name & " with index " & pg.PageIndex
        End If
    Next
End Sub

hth
Mark
 

whdyck

Registered User.
Local time
Today, 17:48
Joined
Aug 8, 2011
Messages
169
Thanks, Mark. Just what I need!
 

Users who are viewing this thread

Top Bottom