I have one form in my Access 2010 application (the Master Form) which opens when the application opens and remains open throughout. I want this form to be always maximised, and to resize when the Access window is resized, which I achieve with Docmd.maximize (in both the Open and Activate event). Minmax buttons are disabled, and the form isn't resizeable. Autocenter, AutoResize and FitToScreen are all True. It has No Borders and is not Moveable.
There are other forms (the Secondary Forms) in the application which open as Modal forms; I want these NOT to be able to be maximised nor minimised, but to be resizeable. They can't be opened as Pop-up forms because the user needs to access commands on the ribbon to use them effectively. Autocentre is False, AutoResize is True and FitToScreen is True. Border Style is Sizeable; MinMax buttons are disabled.
The database has "Overlapping windows" rather than "Tabs" and I want it to remain that way, so that the users can view the context in the Master Form when working in a Secondary Form. The problem is, when a Secondary Form opens, it opens maximised. If the secondary form is resized (either by the user or using docmd.restore), the Master Form un-maximises and doesn't change size with the Access window; it re-maximises when the Secondary Form closes.
I have tried using code in the Master Form open event (instead of docmd.maximise) to resize the Master Form to the Access Window as follows:
x1 As Long
y1 As Long
x2 As Long
y2 As Long
Declare Function IsZoomed Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal _
nCmdShow As Long) As Long
Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal _
x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight _
As Long, ByVal bRepaint As Long) As Long
Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
'Use following instead of GetWindowRect
Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect _
As Rect) As Long
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWNORMAL = 1
Public Sub MaximizeRestoredForm(pfrmF As Form)
' Params : pfrmF
100 On Error GoTo PROC_ERR
Dim MDIRect As Rect
' If the form is maximized, restore it.
110 If IsZoomed(pfrmF.hwnd) <> 0 Then
120 ShowWindow pfrmF.hwnd, SW_SHOWNORMAL
130 End If
' Get the screen coordinates and window size of the
' MDIClient area.
'This is the line which is different
140 GetClientRect GetParent(pfrmF.hwnd), MDIRect
' Move the form to the upper left corner of the MDIClient
' window (0,0) and size it to the same size as the
' MDIClient window.
150 MoveWindow pfrmF.hwnd, 0, 0, MDIRect.x2 - MDIRect.x1, MDIRect.y2 - MDIRect.y1, True
160 Exit Sub
170 DisplaySimpleError "MaximiseRestoredForm" 'Report and log the error
180 Resume PROC_EXIT
Using this, the Secondary Forms still open maximised, but can be restored to their default size in VBA (docmd.restore) without affecting the Master Form. However, the Master Form does not resize when the Access window resizes.
I would be happy with a solution that either (a) provided the behaviour I'm looking for or (b) enabled me to use the ribbon in the secondary forms if they are defined as Pop-up forms.