You can use the following technique to simulate maximizing
a window by sizing it as large as possible in the restored, windowed
(non-maximized), state.
The following example demonstrates how to
create and use a sample
Sub procedure called MaximizeRestoredForm to restore a form if it is
maximized, and then to move it to the upper-left corner of the Microsoft Access
client area window and to size it as large as possible.
NOTE: This technique produces a blank section at the top of the form
that is approximately the height and width of a toolbar if the form is opened
in Design view and then switched to Form view. This code works best when the
form is opened from the Database window or through code while running the
application.
- Create a new module and type the following lines in the
Declarations section:
Type Rect
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type
Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, _
lpRect As Rect) 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
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWNORMAL = 1
- Type the following Sub procedure in the module:
Sub MaximizeRestoredForm (F As Form)
Dim MDIRect As Rect
' If the form is maximized, restore it.
If IsZoomed(F.hWnd) <> 0 Then
ShowWindow F.hWnd, SW_SHOWNORMAL
End If
' Get the screen coordinates and window size of the
' MDIClient window.
GetWindowRect GetParent(F.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.
MoveWindow F.hWnd, 0, 0, MDIRect.x2 - MDIRect.x1 + 4, _
MDIRect.y2 - MDIRect.y1 + 4, True
End Sub
- To simulate maximizing a form automatically when it is
opened, set the OnLoad property of the form to the following event procedure:
Sub Form_Load()
MaximizeRestoredForm Me
End Sub
- To simulate maximizing a form called MyForm, use the
following statement in a function or subroutine:
MaximizeRestoredForm Forms!MyForm