ACC2000: Maximizing One Form Maximizes All Forms (210123)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q210123
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SYMPTOMS

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.

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 a document window in Microsoft Excel 2000, all other document windows will also be maximized.

RESOLUTION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. There are several ways to work around this behavior:
  • Set the MinMaxButtons property to None. This prevents users from minimizing or maximizing the form. This also means the default state of the form is maintained when the focus is shifted to the form.
  • Set the PopUp property of the form to Yes. Forms whose PopUp property is set to Yes are not MDI child windows. Pop-up forms float on top of other forms, and are not maximized when an MDI child window is maximized.
  • You can simulate maximizing a form by sizing it as large as possible in a restored state. The following example demonstrates how to use code to restore a form if it is maximized, and then to move the form to the upper-left corner of the Microsoft Access client area window and size it as large as possible.
  1. In a new module, type the following code:
    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
    
    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
    					
  2. Open the Customers form.
  3. Press CTRL+G to open the Immediate window.
  4. In the Immediate window, type the following line, 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.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Open the sample database Northwind.mdb.
  2. Open the Orders and Customers forms.
  3. Maximize the Customers form.
  4. On the Window menu, click the Orders form.

    Note that the Orders form is now maximized.

Modification Type:MajorLast Reviewed:6/23/2005
Keywords:kbnofix kbprb kbProgramming kbusage KB210123