ACC: Maximizing One Form Maximizes All Forms (95/97)

ID: Q147152

The information in this article applies to:

SYMPTOMS

Advanced: Requires expert coding, interoperability, and multiuser skills.

When you maximize a form, all other forms that are open are also maximized. You cannot maximize one form independent of the other open forms.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

CAUSE

Microsoft Access is a multiple document interface (MDI) application. The default behavior for an MDI document is for all child windows to be maximized when one is maximized. This behavior occurs in many applications. For example, if you maximize one group window in Windows Program Manager, any other group window that you select (by using the Window menu) will also be maximized. Or, if you maximize a document window in Microsoft Word for Windows, all other document windows will be maximized as well.

RESOLUTION

There are several ways to work around this behavior:

1. Create a module and type the following lines in the Declarations
   section:

      Option Explicit

      Type RECT
         Left As Long
         Top As Long
         Right As Long
         Bottom As Long
      End Type

      Declare Function IsZoomed Lib "user32" (ByVal Hwnd As Long) As Long
      Declare Function GetWindowRect Lib "user32" (ByVal Hwnd As Long, _
         lpRect As RECT) 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

      Const SW_MAXIMIZE = 3
      Const SW_SHOWNORMAL = 1

2. Type the following procedure:

      Sub MaximizeRestoredForm(F As Form)
         Dim MDIRect As RECT
         Dim RetVal As Long

         ' If the form is maximized, restore it.
         If IsZoomed(F.Hwnd) <> 0 Then
            RetVal = ShowWindow(F.Hwnd, SW_SHOWNORMAL)
         End If

         ' Get the screen coordinates and window size of the
         ' MDIClient window.
         RetVal = 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.
         RetVal = MoveWindow(F.Hwnd, 0, 0, MDIRect.Right - _
            MDIRect.Left - 4, MDIRect.Bottom - MDIRect.Top - 4, True)
      End Sub

3. To test this function, open the Customers form, type the following
   line in the Debug window, and then press ENTER.

         MaximizeRestoredForm Forms!Customers

   Note that the Customers form is resized to cover the entire client
   area of the Microsoft Access Window.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

1. Open the sample database Northwind.mdb.

2. Open the Customers and Orders forms.

3. Maximize the Customers form.

4. On the Window menu, click the Orders form. Note that the Orders form

   is now maximized.

Additional query words:
Keywords          : kbprg kbusage
Version           : 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbprb

Last Reviewed: November 20, 1998