Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239

    Question Unanswered: Disable mouse wheel function

    Hi.

    On controls in a sub form I would like to disable the possibility of using the mouse wheel.
    Can anyone tell me what function that control this ?

    thanks

  2. #2
    Join Date
    Jun 2003
    Location
    UK
    Posts
    68
    I have been using a piece of code with instructions which I think I found on the microsoft website. So its not mine so just follow the instructions and modify where necessary and it works really well:

    Start Microsoft Access.


    Open the sample database Northwind.mdb.


    On the Insert menu, click Module to create a new module in the Visual Basic Editor.


    Add the following code to the module:


    Option Compare Database
    Option Explicit

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

    Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
    (ByVal lpPrevWndFunc As Long, _
    ByVal hwnd As Long, _
    ByVal msg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long) As Long


    Public Const GWL_WNDPROC = -4
    Public Const WM_MouseWheel = &H20A
    Public lpPrevWndProc As Long
    Public CMouse As CMouseWheel

    Public Function WindowProc(ByVal hwnd As Long, _
    ByVal uMsg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long) As Long

    'Look at the message passed to the window. If it is
    'a mouse wheel message, call the FireMouseWheel procedure
    'in the CMouseWheel class, which in turn raises the MouseWheel
    'event. If the Cancel argument in the form event procedure is
    'set to False, then we process the message normally, otherwise
    'we ignore it. If the message is something other than the mouse
    'wheel, then process it normally
    Select Case uMsg
    Case WM_MouseWheel
    CMouse.FireMouseWheel
    If CMouse.MouseWheelCancel = False Then
    WindowProc = CallWindowProc(lpPrevWndProc, hwnd, uMsg, wParam, lParam)
    End If


    Case Else
    WindowProc = CallWindowProc(lpPrevWndProc, hwnd, uMsg, wParam, lParam)
    End Select
    End Function

    On the File menu, click Save . Save the module as basSubClassWindow .


    On the Insert menu, click Class Module .


    Add the following code to the class module:


    Option Compare Database
    Option Explicit

    Private frm As Access.Form
    Private intCancel As Integer
    Public Event MouseWheel(Cancel As Integer)

    Public Property Set Form(frmIn As Access.Form)
    'Define Property procedure for the class which
    'allows us to set the Form object we are
    'using with it. This property is set from the
    'form class module.
    Set frm = frmIn
    End Property

    Public Property Get MouseWheelCancel() As Integer
    'Define Property procedure for the class which
    'allows us to retrieve whether or not the Form
    'event procedure canceled the MouseWheel event.
    'This property is retrieved by the WindowProc
    'function in the standard basSubClassWindow
    'module.

    MouseWheelCancel = intCancel
    End Property

    Public Sub SubClassHookForm()
    'Called from the form's OnOpen or OnLoad
    'event. This procedure is what "hooks" or
    'subclasses the form window. If you hook the
    'the form window, you must unhook it when completed
    'or Access will crash.

    lpPrevWndProc = SetWindowLong(frm.hwnd, GWL_WNDPROC, _
    AddressOf WindowProc)
    Set CMouse = Me
    End Sub

    Public Sub SubClassUnHookForm()
    'Called from the form's OnClose event.
    'This procedure must be called to unhook the
    'form window if the SubClassHookForm procedure
    'has previously been called. Otherwise, Access will
    'crash.

    Call SetWindowLong(frm.hwnd, GWL_WNDPROC, lpPrevWndProc)
    End Sub

    Public Sub FireMouseWheel()

    'Called from the WindowProc function in the
    'basSubClassWindow module. Used to raise the
    'MouseWheel event when the WindowProc function
    'intercepts a mouse wheel message.
    RaiseEvent MouseWheel(intCancel)
    End Sub
    On the File menu, click Save . Save the class module as CMouseWheel .


    Open the Customers form in Design view.


    On the View menu, click Code to view the class module of the form.


    Add the following code to the class module of the form:


    Option Compare Database
    Option Explicit

    'Declare a module level variable as the custom class
    'and give us access to the class's events
    Private WithEvents clsMouseWheel As CMouseWheel

    Private Sub Form_Load()
    'Create a new instance of the class,
    'and set the class's Form property to
    'the current form
    Set clsMouseWheel = New CMouseWheel
    Set clsMouseWheel.Form = Me

    'Subclass the current form by calling
    'the SubClassHookForm method in the class
    clsMouseWheel.SubClassHookForm
    End Sub

    Private Sub Form_Close()
    'Unhook the form by calling the
    'SubClassUnhook form method in the
    'class, and then destroy the object
    'variable

    clsMouseWheel.SubClassUnHookForm
    Set clsMouseWheel.Form = Nothing
    Set clsMouseWheel = Nothing
    End Sub

    Private Sub clsMouseWheel_MouseWheel(Cancel As Integer)
    'This is the event procedure where you can
    'decide what to do when the user rolls the mouse.
    'If setting Cancel = True, we disable the mouse wheel
    'in this form.

    MsgBox "You cannot use the mouse wheel to scroll through records."
    Cancel = True
    End Sub

    On the File menu, click Close and Return to Microsoft Access .


    Save the form, and then close it.

    NOTE: Do not open the form in Form view at this time. If you do, Microsoft Access will stop responding because the Visual Basic Editor has been loaded.


    Quit Microsoft Access.


    Restart Microsoft Access, and open the sample database Northwind.mdb.


    Open the Customers form in Form view.


    Roll the mouse wheel.


    Note that you receive the message:
    You cannot use the mouse wheel to scroll through records.
    Also note that the current record has not changed, indicating that the mouse wheel message was not processed by Microsoft Access.

  3. #3
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239

    Wow

    Is this really true?
    Can anyone tell me if there is an option like
    "Mouse Wheel enabled" YES/NO

    thanks

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    Nope...you're out of luck there. You'll have to use API calls to disable the mouse wheel.

    Sorry...


  5. #5
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    Just have a look on this example.
    Attached Files Attached Files

  6. #6
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239

    Angry :-o

    Thanks to all of you

    I go for this solution:
    "Keep your finger away from the mouse wheel"

    sincerely
    Vestigo

  7. #7
    Join Date
    Nov 2003
    Posts
    1,487
    Heh....Duct Tape

  8. #8
    Join Date
    Feb 2004
    Posts
    6
    Super glue works as well, but I've always tried to 'sell' them a non-scrolling mouse when you sell them the software. Explain the scrolling problem, and go from there.

    I just cant believe that they haven't added that into Access 2003.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •