Microsoft KB Archive/141111

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

Article ID: 141111

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q141111



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:

150895 ACC95: Microsoft Access Sample Forms Available in Download Center

175066 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:

  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  Save and close the module. Open the Customers form in Design view.  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  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. 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. Minimize the form and repeat step 6. Note that you receive a False(0) value, indicating the form is minimized.</li> Type the following line in the Debug window, and then press ENTER:

Type Forms!Customers.Maximized=True

Note that the form is immediately maximized.</li> Type the following line in the Debug window, and then press ENTER:

Forms!Customers.Minimized=True

Note that the form is immediately minimized.</li></ol>

<div class="references_section">