Here is a simple method for forcing a form window to open inside another form's window when the parent form is loaded. This can be useful for access applications utilizing a custom user interface.
Note: The below code and provided example use two(2) forms (frmParentWindow and frmChildWindow). You will need to reference your own form names when utilizing the provided code in your projects.
modSetParent (Module Name)
Option Compare Database
Public Const GW_HWNDNEXT = 2
Public Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, _
ByVal hWndNewParent As Long) As Long
To open a form window as a child of of the parent form, place the following code in the On Open event of the child form:
Dim frm As Form
Set frm = Form_frmChildWindow
'// If parent form is open ...
If CurrentProject.AllForms("frmParentWindow").IsLoaded Then
'// Set from as child of parent form window (call SetParent function from modSetParent).
hWndChild = frm.hWnd
Call SetParent(hWndChild, Forms!frmParentWindow.hWnd)
End If
frm.Visible = True
A functional example database can be found at this link: Setting Parent/Child Windows, or on the AccessInsider Examples Page.
Comments have been included with the example code as to provide the readers with a better understanding of the methods used.
0 comments:
Post a Comment