Go Back   DeveloperBarn Forums > Databases > Microsoft Access

Sponsored Links

Discuss "Disabling Mouse Scroll" in the Microsoft Access forum.

Microsoft Access - Microsoft Access is a database for small to medium applications. Learn tips and tricks and best database practices here.


Reply « Previous Thread | Next Thread »
 
LinkBack (2) Thread Tools Display Modes
  2 links from elsewhere to this Post. Click to view. #1  
Old March 16th, 2008, 11:45 AM
AOG123's Avatar
Lightning Master

 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 93
Thanks: 6
Thanked 23 Times in 18 Posts
Rep Power: 1
AOG123 is on a distinguished road

Awards Showcase
Microsoft Access 
Total Awards: 1

Default Disabling Mouse Scroll

One of the biggest problems for data accuracy in MS Access in the Mouse Scroll Wheel. A user can often scroll to the wrong record indivertibly.

Examples found across the net usually include modified Dll files,.. this would mean that all pcs running the db would need this modified Dll.

This example solves the problem without having to change any system files.

Please note, I suggest you add this to the forms last,.. as the mouse wheel needs to unhook and there for, requires db shutdown before continuing.


Code:
Create 2 Modules,

Option Compare Database
Option Explicit

Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
    (ByVal hwnd As Long, _
    ByVal nIndex As Long, _
    ByVal dwNewLong As Long) As Long

Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
    (ByVal lpPrevWndFunc As Long, _
     ByVal hwnd As Long, _
     ByVal msg As Long, _
     ByVal wParam As Long, _
     ByVal lParam As Long) As Long
     
     
Public Const GWL_WNDPROC = -4
Public Const WM_MouseWheel = &H20A
Public lpPrevWndProc As Long
Public CMouse As CMouseWheel

Public Function WindowProc(ByVal hwnd As Long, _
    ByVal uMsg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long) As Long

    'Look at the message passed to the window. If it is
    'a mouse wheel message, call the FireMouseWheel procedure
    'in the CMouseWheel class, which in turn raises the MouseWheel
    'event. If the Cancel argument in the form event procedure is
    'set to False, then we process the message normally, otherwise
    'we ignore it.  If the message is something other than the mouse
    'wheel, then process it normally
    Select Case uMsg
        Case WM_MouseWheel
            CMouse.FireMouseWheel
            If CMouse.MouseWheelCancel = False Then
                WindowProc = CallWindowProc(lpPrevWndProc, hwnd, uMsg, wParam, lParam)
            End If
           
            
        Case Else
           WindowProc = CallWindowProc(lpPrevWndProc, hwnd, uMsg, wParam, lParam)
    End Select
End Function
Code:
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
Add this to the events on your form,

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
Attached Files
File Type: zip Scroll_Off_and_On.zip (32.7 KB, 71 views)

Last edited by AOG123; July 23rd, 2008 at 04:36 AM.
Reply With Quote
The Following User Says Thank You to AOG123 For This Useful Post:
jchrisf (June 26th, 2008)
Sponsored Links
  #2  
Old June 26th, 2008, 06:24 AM
Barn Newbie
 
Join Date: Apr 2008
Location: Lake County, IL
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
alansidman is an unknown quantity at this point
Default

Does the events code need to be added to ALL Forms including subforms or is it adequate to only add it to the primary/master forms?
Reply With Quote
  #3  
Old June 26th, 2008, 08:00 AM
AOG123's Avatar
Lightning Master

 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 93
Thanks: 6
Thanked 23 Times in 18 Posts
Rep Power: 1
AOG123 is on a distinguished road

Awards Showcase
Microsoft Access 
Total Awards: 1

Default

Hi,. it depends on what your sub form is doing, as a rule of thumb if you are using a Single Form sub to enter records you will have to lock it,. if the sub is purely for returning data,. i.e. vendor information based on a id,. you can simply use

[Forms]![Form]![ID] and groupby in your sub query to stop the scroll.

Once again the above depends on your query design,. and may not be nessasary if you have already used total by.

If you have a continuous sub form you don't want to use the scroll lock.

Please note you will need to close the db after editing any forms which contain the scroll lock as they need to be unhocked correctly.

Comments on this post
alansidman agrees: Thanks for the input. It is for data entry so I will need to do a lot of cutting and pasting.
Reply With Quote
  #4  
Old July 22nd, 2008, 05:20 PM
Barn Newbie
 
Join Date: Jul 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
KenHigg is an unknown quantity at this point
Default

Can you do a simple flow on how this works. I'm not well versed on using classes, windows stuff, etc.

i.e.

1. The form is 'hooked' to a windows event,
2. The event is analyzed,
etc, etc,...

Thanks,
ken
Reply With Quote
  #5  
Old July 23rd, 2008, 04:39 AM
AOG123's Avatar
Lightning Master

 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 93
Thanks: 6
Thanked 23 Times in 18 Posts
Rep Power: 1
AOG123 is on a distinguished road

Awards Showcase
Microsoft Access 
Total Awards: 1

Default

Have a look at the lines commented out,. "I have highlighted them Blue for you".

Thanks AOG
Reply With Quote
  #6  
Old July 23rd, 2008, 07:39 AM
Barn Newbie
 
Join Date: Jul 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
KenHigg is an unknown quantity at this point
Default

Ok. Thanks. I'll give it a whirl.

ken
Reply With Quote
  #7  
Old July 23rd, 2008, 12:44 PM
Barn Newbie
 
Join Date: Jul 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
KenHigg is an unknown quantity at this point
Default

I did this:

Sample, moved to page 8 - Moderated AOG123 Original Disable Scroll, by KenHigg

Hope it helps somebody else -

Last edited by AOG123; July 24th, 2008 at 09:59 AM.
Reply With Quote
  #8  
Old July 23rd, 2008, 02:49 PM
sbenj69's Avatar
Moderator

 
Join Date: Mar 2008
Posts: 84
Thanks: 20
Thanked 24 Times in 19 Posts
Rep Power: 1
sbenj69 is on a distinguished road

Awards Showcase
Microsoft Windows Microsoft Access 
Total Awards: 2

Default

OK, that's not really disabling the mouse scroll though......

To illustrate this, instead of closing the form each time, allow "Add new records" to this form. Throw a command button out there that just opens a new record. Now add about 3 or 4 records, and scroll through with the mouse.

Data-Entry set to yes, while it locks out the records already in the database, upon open, you can scroll through the records you have just entered.

I modified your examples to just start a new record, to show you.
Attached Files
File Type: zip disable_scroll.zip (17.9 KB, 12 views)
File Type: zip Original disable_scroll.zip (16.2 KB, 6 views)

Last edited by AOG123; July 24th, 2008 at 09:57 AM.
Reply With Quote
  #9  
Old July 23rd, 2008, 09:33 PM
Barn Newbie
 
Join Date: Jul 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
KenHigg is an unknown quantity at this point
Default

If you want to add new records(plural), why would you want to disable the scoll wheel to begin with?
Reply With Quote
  #10  
Old July 24th, 2008, 09:47 AM
AOG123's Avatar
Lightning Master

 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 93
Thanks: 6
Thanked 23 Times in 18 Posts
Rep Power: 1
AOG123 is on a distinguished road

Awards Showcase
Microsoft Access 
Total Awards: 1

Default

Ken,.

Thankyou for offering your alternate view on a solution to this problem.

Unfortunately in my honest opinion your sample doesn't really solve a great deal. The fact is developers will not design a database using DataEntry in all their forms.

Most applications will involve returning to a record at some stage to add or edit data. And it is in theses cases the scroll lock needs to be enforced to maintain data accuracy.

At this stage if the scroll is a problem you have 3 choices,. a modified mousewheel hock dll, the above example, or you simply develop the application under a better platform such as .net
Reply With Quote
Reply

  DeveloperBarn Forums > Databases > Microsoft Access

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

LinkBacks (?)
LinkBack to this Thread: http://www.developerbarn.com/microsoft-access/7-disabling-mouse-scroll.html
Posted By For Type Date
Disabling Mouse Wheel Scroll in Access - ASP Free This thread Refback June 22nd, 2008 11:02 PM
Scroll Bars - ASP Free This thread Refback June 19th, 2008 12:22 PM


All times are GMT -4. The time now is 05:59 PM.



Content Relevant URLs by vBSEO 3.2.0