The .NET Developer Community

Using the mouse's scroll button instead of the form's scroll bar in MS Access

rated by 0 users
This post has 0 Replies | 0 Followers

bungee41
Top 500 Contributor
DFW, Texas
Since 6/26/2003
Posts 281
Reputation 4,060
This FAQ tells you how to write code to enable the use of the mouse's scroll button, in addition to the standard scroll bars on the right of the screen. It is for MS Access users. My example was made in Access 2002.

You must first download and install the 32-bit version of the MsgHook ActiveX control before the code will work properly.

* * * * * * * * * * * * * * *

- Create a new Access Database Project and open a new form in Design view. Save the form as "Form1".

- Click on "Insert", "ActiveX Control..." Scroll down to "MsgHook Control" and click "OK".

- It doesn't matter where you put this control or what the size is. Rename this control to "MsgHook1".

- Click on "View", "Code" to edit the VB code for this form.

- The following code will enable the use of the mouse's scroll button.

* * * * * * * * * * * * * * *

NOTE: The Intellisense popup that is displayed when typing "MsgHook1." in the code does not include the parameters we will use, but it will still work.


Code:
Option Compare Database

Private Const WM_MOUSEWHEEL = &H20A
Private Const WM_VSCROLL = &H115
Private Const SB_LINEUP = 0
Private Const SB_LINEDOWN = 1


'This could not be named MouseWheel() because the term MouseWheel is already defined in Access
'Look under the Access Help for more information on MouseWheel
Public Sub MouseWheel1(ByVal MouseKeys As Long, ByVal Rotation As Long, _
  ByVal Xpos As Long, ByVal Ypos As Long)

    If Rotation > 0 Then
        'scroll up
        MsgHook1.InvokeWindowProc WM_VSCROLL, SB_LINEUP, 0
    Else
        'scroll down
        MsgHook1.InvokeWindowProc WM_VSCROLL, SB_LINEDOWN, 0
    End If

End Sub


Private Sub msghook1_Message(ByVal msg As Long, ByVal wp As Long, _
  ByVal lp As Long, result As Long)

    Select Case msg
        Case WM_MOUSEWHEEL
        '
        'MouseKeys --> wp And 65535
        ' Rotation --> wp / 65536
        ' Xpos --> lp And 65535
        ' Ypos --> lp / 65536
        '
        'MyForm.MouseWheel MousKeys, Rotation, Xpos, Ypos
        '
            Me.MouseWheel1 CLng(wp And 65535), CLng(wp / 65536), _
              CLng(lp And 65535), CLng(lp / 65536)
    End Select

End Sub


'This enables the control
Private Sub Form_Load()

    MsgHook1.HwndHook = Me.hWnd
    MsgHook1.Message(WM_MOUSEWHEEL) = True

End Sub


'This disables the control
Private Sub Form_Unload(Cancel As Integer)

    MsgHook1.Message(WM_MOUSEWHEEL) = False
    MsgHook1.HwndHook = 0

End Sub


Thanks so much to great_llama for all your help. Attached is a small program that shows this.
- bungee41

Page 1 of 1 (1 items) | RSS
Copyright 1998-2017 vbCity.com LLC