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

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 doesn't have properties to determine 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. This method uses 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:

Q150895 ACC95: Microsoft Access Sample Forms Available in Download Center

Q175066 ACC97: Microsoft Access 97 Sample Forms Available in Download Center


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, 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 


  2. Save and close the module.


  3. Open the Customers form in Design view.


  4. 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 


  5. 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 8.


  6. 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.


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


  8. Type the following line in the Debug window, and then press ENTER:
    Type Forms!Customers.Maximized=True
    Note that the form is immediately maximized.


  9. 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.

Additional query words:

Keywords : kbusage FmsHowto
Version : WINDOWS:7.0,97
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: November 2, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.