Try this if you want to know if it is contained at
any level e.g. control inside a frame inside a frame.
Public Function IsContainedIn(objContained As Object, _
objContainer As Object) As Boolean
'*****
' objContained is to be tested for being contained in
' objContainer.
'*****
Dim objW As Object
'*****
'* climb up Container tree until a container
'* matches the one being tested or we reach the top container.
'*****
Set objW = objContained
Dim objWContainer As Object
Dim lngErr As Long
Do
If TypeOf objW Is Form Then ' at the top of the container chain
IsContainedIn = False
Exit Do
End If
' If our container is one being checked then we are contained
On Error Resume Next
' e.g. DataControl has no Container Property
Set objWContainer = objW.Container
lngErr = Err
On Error GoTo 0
If lngErr Then Exit Do ' No container property
If objWContainer Is objContainer Then
IsContainedIn = True
Exit Do
End If
' Climb up to the next container
Set objW = objWContainer
Loop
End Function
Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript