- database solutions and downloads for microsoft access

Prevent the Mouse Wheel scrolling

Stop mouse wheel from scrolling through records in a Microsoft Access form:

Have you ever wanted to prevent your Microsoft Access database users from scrolling through form records with the mouse wheel. It can becoming quite an annoyance when they're editing a record and (for some reason) they use the mouse wheel and zoom to another record.

The following example uses the MouseHook DLL file that is a standard Windows DLL. Do not try to Register it or set a Reference to it from within Access.

The example is adapted using code from Stephen Lebans MouseWheelOnOff sample. Take a look around Stephen's site as there are many good Microsoft Access sample files available.

With our example, we have disabled the Mouse Wheel from scrolling through the records in the Microsoft Access form, when the Form loads.

This is simply done by using the following code sample, attached to the OnLoad event of the Form:

Private Sub Form_Load()
' Turn the MouseWheel Off
Dim blRet As Boolean
' Call our MouseHook function in the MouseHook dll.
' Please note 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!
    blRet = MouseWheelOFF(False)
End Sub

To implement this feature, all you need to do is to ensure that the MouseHook.dll file that is stored in the downloadable zip file is stored in the same location as the database file. You will then need to import into your own MDB the standard code module "modMouseHook" found in the sample MDB included in the download zip file.

Add the code to the Onload event of the form that you are working on to prevent the user from using the mouse scroll wheel.

An example of this can be found in the Microsoft Access 2000 download file available from either the Microsoft Access Downloads page or from the Microsoft Access Modules page.