ACC: How to Determine If a Form Is Maximized or Minimized

Last reviewed: October 24, 1997
Article ID: Q141111
The information in this article applies to:
  • Microsoft Access versions 7.0, 97

SUMMARY

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

Microsoft Access provides no properties for determining if a form or report is maximized or minimized. This article shows you how to create custom form properties that determine if a form window is maximized or minimized using Windows application programming interface (API) functions.

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.

NOTE: This article explains a technique demonstrated in the sample files, FrmSampl.exe (for Microsoft Access for Windows 95 version 7.0) and FrmSmp97.exe (for Microsoft Access 97). For information about how to obtain these sample files, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q150895
   TITLE     : ACC95: Microsoft Access Sample Forms Available on MSL

   ARTICLE-ID: Q175066
   TITLE     : ACC97: Microsoft Access 97 Sample Forms Available on MSL

MORE INFORMATION

By using the Property Get and Property Let statements in Visual Basic for Applications, you can create custom form properties. You can use the Property Get statement to define and retrieve the value of a custom form property. You can use the Property Let statement to set the value of the custom property.

The following example demonstrates how you can use the IsZoomed() and IsIconic() Windows API functions to determine if a form is maximized or minimized and how you can use custom form properties to retrieve and set these values:

  1. Open the sample database Northwind.mdb.

  2. Create a module and type the following lines in the Declarations section, if they are not already there:

          '=================================================================
          'Module Declarations section
          '=================================================================
    

          Option Compare Database
          Option Explicit
    

          Declare Function IsZoomed Lib "User32" (ByVal hWnd As Long) As _
    
               Integer
          Declare Function IsIconic Lib "User32" (ByVal hWnd As Long) As _
               Integer
    
    

  3. Save and close the module.

  4. Open the Customers form in Design view.

  5. On the View menu, click Code, and type the following code in the form module:

          '===================================================================
          'Property Maximized
          '
          'This procedure uses the Property Get statement to define the custom
          'form property 'Maximized' by calling the IsZoomed() function.
          '
          'Return Value:
    
          '    True(-1) - The form is maximized.
          '    False(0) - The form is not maximized.
          '
          '====================================================================
    
          Public Property Get Maximized() As Integer
               Maximized = IsZoomed(Me.hWnd) * -1
          End Property
    
          '====================================================================
          'Property Minimized
          '
          'This procedure uses the Property Get statement to define the custom
          'form property 'Minimized' by calling the IsIconic() function.
          '
          'Return Value:
          '    True(-1) - The form is minimized.
          '    False(0) - The form is not minimized.
          '
          '====================================================================
    
          Public Property Get Minimized() As Integer
               Minimized = IsIconic(Me.hWnd) * -1
          End Property
    
          '===================================================================
          'Property Maximized
          '
          'This procedure uses the Property Let statement to set the value of
          'the custom form property 'Maximized'. The IsMax argument must be
          'defined as the same data type returned by the corresponding Property
          'Get procedure for the same custom property.
          '
          '====================================================================
    
          Public Property Let Maximized(IsMax As Integer)
               If IsMax Then
                   Me.SetFocus
                   DoCmd.Maximize
               Else
                   Me.SetFocus
                   DoCmd.Restore
               End If
          End Property
    
          '====================================================================
          'Property Minimized
          '
          'This procedure uses the Property Let statement to set the value of
          'the custom form property 'Minimized'. The IsMin argument must be
          'defined as the same data type returned by the corresponding Property
          'Get procedure for the same custom property.
          '
          '====================================================================
    
          Public Property Let Minimized(IsMin As Integer)
               If IsMin Then
                   Me.SetFocus
                   DoCmd.Minimize
               Else
                   Me.SetFocus
                   DoCmd.Restore
               End If
          End Property
    
    

  6. Open the Customers form in Form view. Maximize the form.

        NOTE: To test the Maximized property in the Debug window in Microsoft
        Access 97, before opening the Debug window, be sure to set the
        "Debug Window on Top" option. This option is set on the Tools menu by
        clicking Options and then clicking the Modules tab. This option must be
        set to get the expected results in step 9.
    

  7. Press CTRL+G to invoke the Debug window, type the following line in the Debug window, and then press ENTER:

           ?Forms!Customers.Maximized
    

        Note that you receive a True(-1) value, indicating the form is
        maximized.
    

  8. Minimize the form and repeat step 9. Note that you receive a False(0) value, indicating the form is minimized.

  9. Type the following line in the Debug window, and then press ENTER:

           Type Forms!Customers.Maximized=True
    

        Note that the form is immediately maximized.
    

  10. Type the following line in the Debug window, and then press ENTER:

           Forms!Customers.Minimized=True
    

        Note that the form is immediately minimized.
    

REFERENCES

For more information about the Property Get and Property Let statements, search for "Property Get Statement" or "Property Let Statement" using the Microsoft Access Help Index.

Keywords          : kbusage FmsHowTo
Version           : 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 24, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.