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