[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Mouse scroll wheel clears input form data

Posted on 2005-04-05
Medium Priority
Last Modified: 2008-01-09
I have an input only form with combo boxes, text boxes, and so on. The form is built so it doesn't save any data until the user clicks the save button.

The problem that has popped up is if a user uses the mouse scroll wheel during the input process even when focus is in a text or memo box it clears the entered form data and they lose all the input to that point.

Is there a simple way to catch and stop this from happening? I have looked at posts to stop the mouse wheel from moving through recordsets but I don't know if this is the right code for what I need also.

I need input from your great minds on this one, thanks
Question by:AZweb

Accepted Solution

fefo_33065 earned 2000 total points
ID: 13714059

This is  a code I got from the Microsoft website and it has been working fine with my projects.

Create a CLASS module (tools > Macro > Visual Basic Editor > right-click on Modules (look for Project Explorer, then in the Project Explorer window select Modules) > INSERT > Class Module

1) In the new class module paste:
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

    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

    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
'========================================= End class module

2)Save class module. Name it :


3)In the form you want to disable the mouse wheel paste this in the declarations section (very top under compare database):

Option Explicit
Private WithEvents clsMouseWheel As CMouseWheel

4)In the form On Open argument paste
    Set clsMouseWheel = New CMouseWheel
    Set clsMouseWheel.Form = Me

5) Anywhere in the code of the form paste:

Private Sub clsMouseWheel_MouseWheel(Cancel As Integer)
     MsgBox "You cannot use the mouse wheel to scroll through records.", , "Your Title"
     Cancel = True
End Sub

6) In the On Close of the form paste:

    Set clsMouseWheel.Form = Nothing
    Set clsMouseWheel = Nothing

This should do it.

LVL 11

Expert Comment

ID: 13714092
Here's the QB article link: http://support.microsoft.com/?kbid=278379

Expert Comment

by:Jonathan Kelly
ID: 13714947
have you tried setting the cycle property of the form to 'Current Record' ?
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.


Author Comment

ID: 13719181
setting cycle property to 'Current Record' diddn't help but using 'Current Page' helped but is not the final answer.

Expert Comment

ID: 13721074
Current Page will not help if you need to use contiguous forms. At least it did not work for me

Expert Comment

by:Jonathan Kelly
ID: 13724860
maybe a mouse without a mouse wheel

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question