Mouse scroll wheel clears input form data

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
LVL 4
AZwebAsked:
Who is Participating?
 
fefo_33065Commented:
AzWeb,

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
    'module.

    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
    'crash.

    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 :

CMouseWheel


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
    clsMouseWheel.SubClassHookForm

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:

    clsMouseWheel.SubClassUnHookForm
    Set clsMouseWheel.Form = Nothing
    Set clsMouseWheel = Nothing

This should do it.



0
 
Jokra_the_BarbarianCommented:
Here's the QB article link: http://support.microsoft.com/?kbid=278379
0
 
Jonathan KellyCommented:
have you tried setting the cycle property of the form to 'Current Record' ?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
AZwebAuthor Commented:
setting cycle property to 'Current Record' diddn't help but using 'Current Page' helped but is not the final answer.
0
 
fefo_33065Commented:
Current Page will not help if you need to use contiguous forms. At least it did not work for me
0
 
Jonathan KellyCommented:
maybe a mouse without a mouse wheel
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.