Black and White Inc logo


MouseWheel.dll is a support library for Access programs. It is discussed and described fully in KB 278379 and KB 308636 at I am most grateful to John Viescas, author of "Running Microsoft Access 2000" and "SQL Queries for Mere Mortals" for telling me about these articles.

The problem it solves in Access is quite annoying: If you are using an edit form to edit a record and you bump the mouse wheel, you lose the data you edited and move randomly to some other record. Using the technique described here you can trap and discard mouse wheel messages for all edit forms and header forms, while leaving the browse forms as they are. The mouse wheel can then be used to move through browse forms, without causing chaos in the edit forms.

Note: the dll used is not a mouse driver, and should not interfere with any mouse drivers. Workstations without a mouse with a mouse wheel should no experience any problems either. The Mousewheel.dll file is only 24k in size. You can also use it as described in a VB6 program, but it doesn't seem to be necessary because a standard VB form doesn't respond to the mouse wheel.

All I have done is followed the instructions and created the DLL file, as described in the article "How to Prevent Use of the Mouse Wheel to Scroll Through Records". I have then created an install package using the standard Package and Deployment Wizard in VB6. Please note the disclaimer from Microsoft: "Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose." In the same way, this download is intended for Miami programmers, and users of the Drive Catalogue program.

You can ZIP format compressed filedownload version 1.00.0001 here, at no charge. The download is just the VB install program, and does not include source code, and is 1377kb in size. You can also download just the ZIP format compressed file, and use regsvr32 to register it in your windows system directory. It contains MouseWheel.dll and some install instructions.

Install Instructions for Miami Users

You only need to modify your fe* and fh* forms. Open a code module and change the Tools -> References options so that the "MouseWheel" reference is also shown.

Replace the usual code at the top of the form that reads:

Option Compare Database
Option Explicit
with the following code:
Option Compare Database
Option Explicit
Private WithEvents clsMouseWheel As MouseWheel.CMouseWheel ' 308636
Private Sub clsMouseWheel_MouseWheel(Cancel As Integer)
'// KB 308636 - ACC97 How to Prevent Use of the Mouse Wheel to Scroll Through Records
    Debug.Print "You cannot use the mouse wheel to scroll records."
Cancel = True
End Sub
Private Sub Form_Load()
Set clsMouseWheel = New MouseWheel.CMouseWheel ' Q308636
Set clsMouseWheel.Form = Me
End Sub
Private Sub Form_Close()
    On Error GoTo NextCmd
' Q308636
Set clsMouseWheel.Form = Nothing
Set clsMouseWheel = Nothing
NextCmd: Err = 0
    On Error Goto 0
Call zFormClose(Form)
End Sub

Then change the form properties so that OnLoad and OnClose are set to "[Event Procedure]"
The simplest way to do this is click on the OnLoad property and press "[". Then use the tab key 3 times to move to "On Close" and press the "[" again.

A standard Mustang form might be slightly different, but the principle is the same. Included in the smaller ZIP format compressed download file is a readme.txt file, and an Access module that will allow Mustang/Miami users to apply the changes mentioned here to their existing or new applications.

Once you have improved your application in this way, you'll notice how much nicer it is to use the mouse wheel to scroll through browse forms using the wheel, without the fear of losing any data or getting weird things happening to your application.

Update: in spite of what was published on this page before, it is not advised to put the mousewheel code on the Menu form or a standard Swichboard form. It isn't needed there anyway, and it seems to cause trouble. The FireMouseWheel event seems to take care of other bugs. If a form generates an error that causes it not to close in the normal way, you may find that Access will not quit correctly. Apart from the "brute force" method of Ctrl-Alt-Del, the more elegant way of fixing the problem is to re-open the program in the copy of Access that won't close, go to any header/subform screen, and then quit. This allows Access to disconnect from the dll in the correct way.



Thanks to the Programmer's Notepad for the basic HTML formatting of this code.

-:| [home] | [free stuff] | [blog] |:-

All information copyright © 2002, 2003 Black and White Inc. All rights reserved. Last Updated: 15/04/2005 0:53