Informatics, Uncategorized

Mess with MS Access reports

When designing a MS Access form you can easily disable the minimize and maximize buttons by selecting the appropriate option in the form’ properties window. Such an option doesn’t exist for Access reports. However you can still mess with these report’ features by making use of VBA and the Win32 API.

To disable the minimize and or maximize buttons of a report window, place the following code in a VBA code module:

Declare Function SetWindowLong Lib "user32" _
    Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal _
    nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function GetWindowLong Lib "user32" _
    Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal _
    nIndex As Long) As Long

Public Const WS_MINIMIZEBOX = &H20000
Public Const WS_MAXIMIZEBOX = &H10000
Public Const GWL_STYLE = (-16)

Then write the following code for the report’ OnOpen event:

Private Sub Report_Open(Cancel As Integer)
    Dim lWnd As Long
  
    lWnd = GetWindowLong(Me.hwnd, GWL_STYLE)
    lWnd = lWnd And Not (WS_MINIMIZEBOX)
    lWnd = lWnd And Not (WS_MAXIMIZEBOX)
    lWnd = SetWindowLong(Me.hwnd, GWL_STYLE, lWnd)
End Sub

Simply comment out one of the lines to disable only the minimize or maximize button.

speak up

Add your comment below, or trackback from your own site.

Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*Required Fields