Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mouse wheel scroll code for two forms

Status
Not open for further replies.
Aug 4, 2004
84
US
Hello, all!

Just let me say that this site again, is amazing. Secondly, I have used the following link from a thread on this site,


to prevent the mouse wheel form scrolling through records. I have the code in one form and want to use it on another form. The code works great, however when I save the new code in VB, the database tells me there is already code saved as this name,(which makes sense) and would you like to replace?

I don't want to replace the code correct? Do I have to change what i save the code as for the new form? For example save as SubClassWindow2 instead of SubCLassWindow?

thanks

AB
 
You should just have to call the module from each form you want to limit scrolling on, not add a module for each one...

Try on each form adding the following (from the Microsoft KB)

Code:
Option Compare Database
Option Explicit

'Declare a module level variable as the custom class
'and give us access to the class's events
Private WithEvents clsMouseWheel As CMouseWheel

Private Sub Form_Load()
    'Create a new instance of the class,
    'and set the class's Form property to
    'the current form  
    Set clsMouseWheel = New CMouseWheel
    Set clsMouseWheel.Form = Me

    'Subclass the current form by calling
    'the SubClassHookForm method in the class
    clsMouseWheel.SubClassHookForm
End Sub

Private Sub Form_Close()
    'Unhook the form by calling the 
    'SubClassUnhook form method in the 
    'class, and then destroy the object
    'variable
  
    clsMouseWheel.SubClassUnHookForm
    Set clsMouseWheel.Form = Nothing
    Set clsMouseWheel = Nothing
End Sub

Private Sub clsMouseWheel_MouseWheel(Cancel As Integer)
     'This is the event procedure where you can
     'decide what to do when the user rolls the mouse.
     'If setting Cancel = True, we disable the mouse wheel
     'in this form.

     MsgBox "You cannot use the mouse wheel to scroll through records."
     Cancel = True
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top