Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2006
    Posts
    2

    Unanswered: Disable mouse wheel

    Could someone telle me, how to disable the mouse wheel control wit vba.
    Is there a docmd. or some other solution?

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    No, Access doesn't have an answer for this, but Leban's does! Courtesy of this site:

    http://www.lebans.com/mousewheelonoff.htm

    Open up a new module and paste in this code; be sure to scroll so you get all the code:



    Code:
    Option Explicit
    
    Private Declare Function LoadLibrary Lib "kernel32" _
    Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
    
    Private Declare Function FreeLibrary Lib "kernel32" _
    (ByVal hLibModule As Long) As Long
    
    Private Declare Function StopMouseWheel Lib "MouseHook" _
    (ByVal hWnd As Long, ByVal AccessThreadID As Long, _
    Optional ByVal bNoSubformScroll As Boolean = False, Optional ByVal blIsGlobal As Boolean = False) As Boolean
    
    Private Declare Function StartMouseWheel Lib "MouseHook" _
    (ByVal hWnd As Long) As Boolean
    
    Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
    
    ' Instance returned from LoadLibrary call
    Private hLib As Long
    
    
    Public Function MouseWheelON() As Boolean
    MouseWheelON = StartMouseWheel(Application.hWndAccessApp)
    If hLib <> 0 Then
        hLib = FreeLibrary(hLib)
    End If
    End Function
    
    Public Function MouseWheelOFF(Optional NoSubFormScroll As Boolean = False, Optional GlobalHook As Boolean = False) As Boolean
    Dim s As String
    Dim blRet As Boolean
    Dim AccessThreadID As Long
    
    On Error Resume Next
    ' Our error string
    s = "Sorry...cannot find the MouseHook.dll file" & vbCrLf
    s = s & "Please copy the MouseHook.dll file to your Windows System folder or into the same folder as this Access MDB."
    
    ' OK Try to load the DLL assuming it is in the Window System folder
    hLib = LoadLibrary("MouseHook.dll")
    If hLib = 0 Then
        ' See if the DLL is in the same folder as this MDB
        ' CurrentDB works with both A97 and A2K or higher
        hLib = LoadLibrary(CurrentDBDir() & "MouseHook.dll")
        If hLib = 0 Then
            MsgBox s, vbOKOnly, "MISSING MOUSEHOOK.dll FILE"
            MouseWheelOFF = False
            Exit Function
        End If
    End If
    
    ' Get the ID for this thread
    AccessThreadID = GetCurrentThreadId()
    ' Call our MouseHook function in the MouseHook dll.
    ' Please not the Optional GlobalHook BOOLEAN parameter
    ' Several developers asked for the MouseHook to be able to work with
    ' multiple instances of Access. In order to accomodate this request I
    ' have modified the function to allow the caller to
    ' specify a thread specific(this current instance of Access only) or
    ' a global(all applications) MouseWheel Hook.
    ' Only use the GlobalHook if you will be running multiple instances of Access!
    MouseWheelOFF = StopMouseWheel(Application.hWndAccessApp, AccessThreadID, NoSubFormScroll, GlobalHook)
    
    End Function
    
    
    '******************** Code Begin ****************
    'Code courtesy of
    'Terry Kreft & Ken Getz
    '
    Function CurrentDBDir() As String
    Dim strDBPath As String
    Dim strDBFile As String
        strDBPath = CurrentDb.Name
        strDBFile = Dir(strDBPath)
        CurrentDBDir = Left$(strDBPath, Len(strDBPath) - Len(strDBFile))
    End Function
    '*********
    *********** Code End ****************
    When prompted name the module modMouseHook

    Use your FIND feature in Windows to make sure you have the file MouseHook.dll on your PC. You should, it's a standard Windows file. You may have to go into Windows and select "Show hidden files" then run FIND.

    This DLL DOES NOT NEED TO BE REGISTERED!!!

    It's a good idea to copy this file to the same folder your db resides in.

    In the Form_Load sub of your form enter the following:


    Code:
    Dim blRet As Boolean
    	' Turn the MouseWheel Off
    	blRet = MouseWheelOFF
    Then in an event, either when your form closes or your database closes, use this code to turn the mousewheel back on:


    Code:
    ' Turn the MouseWheel On
    blRet = MouseWheelON
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    You also might want to do a search on this site for mouse wheel. I think there are a lot of options on this site.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    You'll get a lot of hits on this site and others, the question has been asked beaucoup times, but the answer I posted is the definitive answer.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Definitive answer Missingling? I don't understand. I used a couple of the other techniques and they worked pretty well (one of them included just adding a dll (which also didn't need to be registered) to the directory with a few vba commands and another was only adding just a few command lines). What makes your method definitive? (just curious as there was a post that did the same thing with less code and no dll involved).
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Because in the dozens of times I've seen posts on the subject, here and elsewhere, Leban's solution is the one everyone ends up using. Most people just post the URL for the demo zip file but I just copied and listed the code for the module here. All required, really, is adding the module and one line of code. Can't get much simpler.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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