Using the mouse wheel with Access 2002
Posted on 2004-12-01
We need some help resolving a mouse wheel problem on some of our forms. Currently we are coding to disable it on the BeforeUpdate event of the form but it appears very inconsistent in it's behavior on the forms where it works and with other forms doesn't work at all.
Here is what I'm doing:
1. I created a modular variable in the form called modCancel as Boolean
2. I add this code:
Private Sub Form_MouseWheel(ByVal Page As Boolean, ByVal Count As Long)
modCancel = True
3. I add this code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If modCancel = True Then
MsgBox "You cannot use the mousewheel to scroll through records. Use PageUp and PageDown.", vbOKOnly + vbInformation
Cancel = True
modCancel = False
What this does is when the user scrolls the mouse wheel then the modular variable is set to true and the form beforeupdate automatically fires and the code in there checks to see if the modular variable is true and if so then it sends a message and cancels the event. It also resets the modular variable back to false. This cancels the mouse wheel movement completely with no side effects. I have code behind my key press events to make sure that the PageUp and PageDown don't fail also, but I want the user to be able to use those as a scrolling tool.
The problem is that this works on about half of my data forms and with the other half the form_beforeupdate event doesn't fire until I hit the end of the recordset on the form at the new record (which is a blank record and that is causing the errors that I'm trying to avoid).
Is there a better way of cancelling out the mousewheel event or does anyone know why the beforeupdate events wouldn't be firing? Before you reply know that I've tried the Microsoft KB code and it doesn't work correctly.