Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
Active Form or Active Subform?
From Wiki
Microsoft provides some useful code for detecting whether the active control is on a form or a subform:
ACC2000: Screen.ActiveForm Returns the Main Form, Not the Subform: http://support.microsoft.com/kb/210210/en-us
However, there is a small problem when the control is on a tab control because the parent of a tab control is the page, and the parent of that is the tab control itself. I have fiddled a bit and the addition of a little code seems to clear this up. I have marked the additional code.
<...>
' Get the unique window handle identifying the form
' .. the active control is on.
hWndParent = ctlActive.Parent.Properties("hWnd")
' If the active form window handle is the same as the window
' handle of the form the active control is on, then we are on the
' mainform, so exit.
'==========================Inserted Code===========================
If ctlActive.Parent.ControlType = acPage Then
Set ctlParent = frmActive.Controls(ctlActive.Parent.Parent.Name)
hWndParent = ctlParent.Parent.Properties("hWnd")
End If
'========================End of Inserted Code=======================
If hWndParent = frmActive.Hwnd Then Exit Function
<...>
You will, of course, have to declare ctlParent.
You may also run into problems if you load forms into subform controls at runtime.



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.