Microsoft KB Archive/304312

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

Article ID: 304312

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q304312



For a Microsoft Access 2000 version of this article, see 304313.

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

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

IN THIS TASK
SUMMARY
 * Method 1
 * Method 2



SUMMARY
This article shows you how to remove the control box (the Minimize, Maximize, and Close buttons) from a report preview window.

back to the top

Method 1

 * 1) Open the report in Design view.
 * 2) On the View menu, click Properties.
 * 3) In the report properties combo box, make sure that Report is selected.
 * 4) Click the Format tab.
 * 5) Change the ControlBox property to No.

NOTE: You can remove the Minimize and Maximize buttons or the Close button individually. To do so, set the property for each button to None or to No. Then set the ControlBox property to Yes.
 * 1) When you preview the report, the Control menu does not appear.

back to the top

Method 2
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. Method 2 shows you how to use the Windows API function SetWindowLong to remove the control box from the report window.

The following code sample includes a Declaration section. This Declaration section sets a reference to the function GetWindowLong and to the function SetWindowLong 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, first you use the GetWindowLong function to store the current window style to a long variable. Then, you modify that variable to exclude the control box. The constants of the control box are also included in the Declaration section. Finally, you use the SetWindowLong function to insert the modified long variable into the dwNewLong parameter. This resets the window style.

The Report_Activate event runs before the window has been painted. Therefore the following code displays the window of the report without displaying a control box or a Close button.

NOTE: After you remove the control box from the window of the report, the control box is no longer 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. Then open the report again in Design view.  Open your report in Design view. On the View menu, Click Code.  Type or paste the following code: Private Declare Function SetWindowLong Lib &quot;user32&quot; Alias _ &quot;SetWindowLongA&quot; (ByVal hwnd As Long, ByVal nIndex As Long, _       ByVal dwNewLong As Long) As Long Private Declare Function GetWindowLong Lib &quot;user32&quot; Alias _ &quot;GetWindowLongA&quot; (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. This removes the Close button also. L = L And Not (WS_SYSMENU) 'Also modify the current style, subtracting the 'Minimize & Maximize buttons, by uncommenting the following 'line and commenting the line above. 'If you subtract the Minimize button, the Maximize button is   'also subtacted and vice versa. ''L = L And Not (WS_MINIMIZEBOX) ''L = L And Not (WS_MAXIMIZEBOX) L = SetWindowLong(Me.hwnd, GWL_STYLE, L)

End Sub  Save changes, and then close the report. Preview the report. Note that the control box does not appear.

back to the top

