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

ID: Q210190


The information in this article applies to:
  • Microsoft Access 2000

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

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


SUMMARY

Microsoft Access doesn't have properties to determine if a form or a report is maximized or minimized. This article shows you how to create custom form properties that determine if a form is maximized or minimized. This method uses Windows application programming interface (API) functions.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp


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.

CAUTION: Following the steps in this example will modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and perform these steps on a copy of the database.

  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:


  2. 
    '=================================================================
    '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:


  6. 
    '===================================================================
    '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 
  7. Open the Customers form in Form view. Maximize the form.


  8. Leave the form open and press ALT+F11 to open the Visual Basic Editor .


  9. In the Visual Basic Editor, type the following line in the Immediate window, and then press ENTER:
    
    ?Forms!Customers.Maximized 
    Note that you receive a True (-1) value, indicating the form is maximized.


  10. Return to the Access Database window, minimize the form, and repeat step 6.

    Note that you receive a False (0) value, indicating the form is minimized.


  11. Type the following line in the Immediate window, and then press ENTER:
    
    Forms!Customers.Maximized=True 
    Note that the form is maximized upon returning to the Database window.


  12. In Visual Basic Editor, type the following line in the Immediate window, and then press ENTER:
    
    Forms!Customers.Minimized=True 
    Note that the form is immediately minimized.



REFERENCES

For more information about Property Get and Property Let statements, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type "Property Get, Property Let" in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Additional query words:

Keywords : kbdta AccCon FmsHowto PgmHowto
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


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