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. 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.
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: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.
-
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.
- Leave the form open and press ALT+F11 to open the Visual Basic Editor .
- 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.
- 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.
- 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.
- 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.
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.