Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

HOW TO: Remove the Control Box (System Menu) from a Report Preview Window in Access 2000


View products that this article applies to.

Summary

This article shows you how to programmatically remove the control box (the Minimize, Maximize, and Close buttons) from a report window. In Access 2000, you cannot use the user interface to do this.

NOTE: Microsoft has added this feature to Microsoft Access 2002.

MORE INFORMATION

This article uses the Windows API function SetWindowLong to remove the control box from the report window.

The following code sample includes a Declaration section that sets a reference to the GetWindowLong and the SetWindowLong functions in the User32 API library. These functions set and return the style of the window that is indicated in the hwnd variable.

When you run the code, you first use the GetWindowLong function to store the current window style to a long variable. Then, you modify that variable to exclude the control box, whose constants are also included in the Declaration section. Finally, you use the SetWindowLong function to insert the modified long variable into the dwNewLong parameter to reset the window style.

Because the Report_Activate() event runs before the window is painted, the following code will cause the window of the report to be displayed without a control box or a Close button.

NOTE: After the control box has been removed from the window of the report, the control box will not be available when you switch back to Design view. To return the control box to the report window in Design view, manually close the report window by clicking Close on the File menu, and then re-open the report in Design view.

CODE

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. NOTE: You may have some Microsoft Windows API functions defined in an existing Microsoft Access library; therefore, your declarations may be duplicates. If you receive a duplicate procedure name error message, remove or comment out the declarations statement in your code.
Option Compare Database
Option Explicit
   Private Declare Function SetWindowLong Lib "user32" Alias _
        "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
        ByVal dwNewLong As Long) As Long
   Private Declare Function GetWindowLong Lib "user32" Alias _
        "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) _
        As Long
   
   'Establish constants for elements of the Window.  
   Const WS_MINIMIZEBOX = &H20000 'creates a window with a maximize box
   Const WS_MAXIMIZEBOX = &H10000 'creates a window with a minimize box
   Const WS_SYSMENU = &H80000 'creates window with a System-Menubox in its titlebar.
       
   Const GWL_STYLE = (-16)
       
Private Sub Report_Activate()

            Dim L As Long
            'Get the current style.
            L = GetWindowLong(Me.hwnd, GWL_STYLE)

            'Modify the current style, subtracting
            'the System Menu, thereby removing the Close Button also.
            L = L And Not (WS_SYSMENU)
            
            'Further modify the current style, subtracting
            'the Minimize Button, by uncommenting the following line.  
            ''L = L And Not (WS_MINIMIZEBOX)
            
            'Further modify the current style, subtracting
            'the Maximize Button, by uncommenting the following below.
            ''L = L And Not (WS_MAXIMIZEBOX)
                        
            L = SetWindowLong(Me.hwnd, GWL_STYLE, L)
End Sub
				

↑ Back to the top


References

For additional information about Visual Basic for Applications, click the article number below to view the article in the Microsoft Knowledge Base:
226118 OFF2000: Programming Resources for Visual Basic for Applications

↑ Back to the top


Keywords: KB304313, kbhowtomaster, kbhowto

↑ Back to the top

Article Info
Article ID : 304313
Revision : 2
Created on : 6/23/2005
Published on : 6/23/2005
Exists online : False
Views : 287