MS Access – Enable Mouse Wheel Scrolling of Text Box

I was recently working on a database in which I was displaying a memo field in a text box on a form and was annoyed by the fact that the Mouse Wheel did not work to scroll though its’ content.   Then, I started looking for a setting, a property, to enable it, but there wasn’t one!

Searching the Internet, I found examples to enable it, but they all used SendKeys.  Any experienced programmer knows all to well that SendKeys is to be avoided at all cost, as they are unpredictable and thus very unreliable.  So I went out searching for another solution.

This demo is the results of piecing together various sources of information.

As you will see by dissecting this Demo database, the entire thing is governed by one Standard Module housing a few APIs (GetFocus & SendMessage) and then the addition of a On Mouse Wheel event to the form containing the text box to enable wheel mouse scrolling on.

Hopefully, this can help someone else trying to make the mouse wheel work with a text box.

Disclaimer/Notes:

If you do not have Microsoft Access, simply download and install the freely available runtime version (this permits running MS Access databases, but not modifying their design):

Microsoft Access 2010 Runtime
Microsoft Access 2013 Runtime
Microsoft Access 2016 Runtime
Microsoft 365 Access Runtime

All code samples, download samples, links, ... on this site are provided 'AS IS'.

In no event will Devhut.net or CARDA Consultants Inc. be liable to the client/end-user or any third party for any damages, including any lost profits, lost savings or other incidental, consequential or special damages arising out of the operation of or inability to operate the software which CARDA Consultants Inc. has provided, even if CARDA Consultants Inc. has been advised of the possibility of such damages.

 

Download

Feel free to download a copy (accdb x32/x64) by using the link provided below:

Download “Scrolling Text Box” Scrolling-Text-Box.zip – Downloaded 30760 times – 29.07 KB
Finally Fixed
In a recent test of Access 2019, Textboxes appears to now scroll properly by default, so Microsoft has finally addressed this issue. That said, based on comments below it does not seem to work with Rich Text content though (I haven’t tested).

Version History

Version Date Summary of Changes
V1.000 2014-01-22 Initial release
V1.001 2017-02-09 Changed the Copyright so make it open to all to use (I had omitted this – Sorry!)
Added Error Handling
Minor code optimization/cleanup
V1.002 2019-02-07 Simplified the overall code
Adjusted the code to work with tab controls as well, per comments provided below
V1.003 2022-07-12 Cleaned up API Declarations to use Microsoft’s version
Added conditional compilation so it works in both 32 and 64-bit installations
V1.004 2022-10-13 Create a Standard Behavior form
Created a Main form to house both example as a comparison

76 responses on “MS Access – Enable Mouse Wheel Scrolling of Text Box

  1. Kael Dowdy

    This was exactly what I was looking for. Simple API calls and works like a charm.

    Thanks for putting this together!

  2. Harris

    Thank you very, very much for solving this vexing problem with such an incredibly useful piece of coding! Works like a charm.

  3. Random Citizen

    Thank you very much, for sharing this code. Was searching for a solution which doesn’t use SendKeys and then I found this beauty.

    Works also perfectly with Access 2010.

    Greetings

  4. Laser FX

    Thanks so much for this code to get the mouse wheel scrolling in a form text box. I had looked for a way to solve this a few years ago, but failed; so I’m delighted to have found this. I’m not very experienced with VBA – but even I managed to get it to work, (on the 2nd attempt) ! Many thanks.

  5. graziano

    Please could you tell me how do i insert the code in my db?
    I’m not an Access Expert, but i’m working with Access 2013 and i have lot of textbox with many rows and scroll with mouse help me a lot.

    Thanks!

    1. Daniel Pineault Post author

      Your best bet is to review the demo database carefully and then implement the same setup within your database.

  6. Krishna

    Thanks for doing this Dan. You definitely get good karma points (:-) !
    Minor glitch … I am running 64-bit version and the two Declare statements required the word “PtrSafe” to be inserted between “Declare” and “Function”.

    Thanks again!

    1. Anon

      I couldn’t get the code to work until I tried this. Thank you Daniel for the wonderful workaround and thank you Krishna for the added the tip! The code works beautifully!

    2. Ron

      Thank you!!! I was just getting this set up and got sad thinking it was only 32 bit compatible for some reason. Adding that fixed my errors as well. My user experience will be so much better with this!

  7. winfirst

    This worked out great for my database as this has always annoyed me when I needed to review text in a form. Thank you very much for posting this helpful tip. It has made working in my database much smoother.

  8. Sam Whiten

    Thank you so much for this great sample, it works flawlessly!

    One question if I may, is there a way to suppress the annoying sound Access does every time it tries to scroll more than the textbox allows? Say I’m on top and I try to scroll up (happens even when manually clicking the up arrow) the errors sounds, even if I’m one or two lines in, because this code tries to scroll three lines at a time it’ll scroll to the top and then does the sounds the error thingy.

    I can assume that a solution can come from having the code checking the scrollbar position and acting accordingly, although I’m not sure how to do it.

    Thanks!

  9. William

    Thank you for sharing this solution! It works great and will save the primary user (me) at lot of time.

  10. Greg

    I have been trying to get this functionality for 2 days. Took me about 20 minutes with your help. I can’t thank you enough!!

  11. Peter Gillanders

    Click on the record selector and try to scroll, and I get Run-time error ‘2474’ with the message “the expression you entered requires the control to be in the active window”.
    Debug indicates the problem is on the line :
    If ActiveControl.Properties.Item(“controltype”) = acTextBox Then

    More investigation after this evenings meeting

  12. Peter Gillanders

    So, I added the line :
    On Error Resume Next
    to the start of Sub Form_MouseWheel, and that SEEMS to have got round the problem of Run-time error 2474.
    It does mean that with the record selector selected, the scroll wheel does nothing. On a form where all the controls are text boxes, this could be problematic.

  13. Ron F.

    Hi,

    Thanks for this very fine code, it works quite good. For me as a VBA-starter it is very nice to find good working code on the internet!

    I have a question: is it possible to avoid the ‘beeps’ when reached the beginning or ending of the textbox? I tried Docmd.setWarnings false, but this doesn’t work.

    By the way: sorry for my poor English, I am Dutch…..

    Kind Regards,
    Ron

    1. Daniel Pineault Post author

      I’m not sure what to tell you as I have never experienced such an issue.

      What version of Access are you using?
      What OS?
      Can you give me exact steps to reproduce the issue?

  14. Gerd

    Vielen Dank für die tolle Lösung. Nach Übernahme von mod_ScrollingTextBox und der Private Sub Form_MouseWheel(ByVal Page As Boolean, ByVal Count As Long) funktionierte das Scrollen sofort.
    Großartig !!

    Thanks for the great solution. After mod_ScrollingTextBox and the Private Sub Form_MouseWheel (ByVal Page As Boolean, ByVal Count As Long), the scrolling functioned immediately.
    Great !!
    — Translated using Google Translate

  15. Ken Gosse

    Many thanks. I taught my self Access programming in the mid 90’s and had two jobs for a short time in 98-2000 modifying and creating databases to prepare for Y2K. I lost one due to company bankruptcy and the other because the company was sold in Dec 99, but my task was essentially completed. Then the dot.com bubble burst and that ended my short foray. It’s been 16 years since I did any programming and now do it for my personal use and recreation. I owe a lot to many web sites and look forward to learning more from yours. I don’t know what makes the scroll wheel code tick, but I had no problem importing it to my project (adding my comments to yours to note when and where I found the download). It works fine and I’ve been able to edit various textboxes on my main form. I was really surprised when I got Office 2016 (my last Access was 2000) and found out scrolling on Access forms hadn’t been incorporated as a standard feature. This will help a lot.

  16. Bob

    First of all, let me say JOB WELL DONE.

    I used the code in my current project and it worked fine until I put the Textbox in the Tab Control. The scrolling Textbox somehow don’t work well when the Textbox is inside the Tab Control.

  17. Arlene

    Thank you so much! After days of frustration, I was ready to give up, and then voila! your code saved my sanity. If I may ask, is there an equally simple way to get it to work for a text box that is in a Tab Control sheet? (The text box outside the tab control work perfectly, but not the one inside.) Thanks again

  18. Doug Blacker

    Awesome, Daniel. Dropped right in to my code snippets db.
    Access 2010 & 2016, Windows 10 Pro x64
    Thank you for sharing.

  19. Sam

    thank you.
    when a text box is inside of TabControl it doesn’t work as Arlene posted. I hope somebody has a solution for it.

  20. Marc

    Muchísimas gracias por compartir este código!
    Es magnifico!! Hacia muchos años que deseaba resolver esto.

    Una sugerencia, con su permiso:
    seria fantástico que implementara en el código la forma de evitar el molesto beep cuando se alcanza el principio o final del texto. Muchas gracias

    Google Translate:
    Thank you very much for sharing this code!
    It’s great! For many years I wanted to solve this.

    A suggestion, with your permission: it would be great if you could implement in the code the way to avoid the annoying beep when the beginning or end of the text is reached. Thank you very much

  21. THG

    Thank you! This has been bugging me for years!
    I recently upgraded to Access 2016 from 2007 from 2003…
    Thinking MS would incorporate this function long ago.
    Work perfectly!

  22. Paul

    Thank you. Works perfectly.
    But i have the same problem as Arlene and Sam : doesn’t work on a textbox inside a TabControl.

  23. Ben

    Thank you Daniel for this great solution. Your addition of error handling in v1.01 may have had a side effect if the previous method was On Error Resume Next….

    @Peter Gillanders: I also get error 2474 if I click on the Navigation Pane, and then hover my mouse above a form textbox and use the scroll wheel. I tried checking Screen.ActiveForm but it is still pointing to the ActiveForm. My solution was to add a special case in the Form_MouseWheel() error handler to Resume Next on error 2474.

    @Paul, Arlene, Sam: I added a tab control to the sample database and copied the txt_SomeText control into a few tabs. The scrolling works fine for me. I’m using Access 2016 32-bit (16.0.9126.2336)

  24. Paul

    Ben,
    I tried to copy the txt_SomeText control into aan tab control, but still doesn’t work on my computer.
    I am using Office 365 Click To Run version 1812, Access 16.0.11126.20192 32-bit

    Paul

    1. Daniel Pineault Post author

      You need to copy the mod_ScrollingTextBox module into your database. Then add the Form_MouseWheel event code to your form’s Form_MouseWheel event. Then it should work.

      1. Paul

        Daniel,
        Like Ben, I used the sample Database. Besides the txt_SomeText control I created a Tab Control with three tabs and copied the textbox intoeach tab. The scrolling in the textbox outside the tab control works perfectly., but when trying to scroll the textbox inside the tabcontrol it only scrolls two lines and then select the whole text and stopt scrolling.

        My native language is Dutch, so I am using Access in Dutch (sorry for my bad English)

        Paul

        1. Paul

          It works ! When I remove the line – ctl.Setfocus – From the Function fhWnd in the Mod_ScrollingTextBox it works perfectly for the textbox inside and outside the Tab control.

          Paul

  25. Marek Czerski

    Hi, Daniel,
    I want to join the large choir of people who praise you for your generous help and excellent piece of code. Thank you for the tool that I would not be able to write by myself and now I may enjoy reading large text boxes easily thanks to your code. That’s really great!!!
    Best regards
    Marek

  26. Dave Taylor

    Hi, I tried to impliment this code but it is for 32 bit machines only and I get an error of course. Do you have a 64 bit version by chance? Thanks.

    1. Daniel Pineault Post author

      You’d need to use the 64-bit versions of the API Declarations, I think that would be

      Public Declare PtrSafe Function apiGetFocus Lib "user32" () As LongPtr
      Public Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
  27. Christian Rondeau

    Hi,
    thanks!!!

    But it don’t work in Access runtime 2010… It say’s:
    The expression On Mouse Wheel you entered as the event property setting produced the following error:
    This error occurs when an event has failed to run because the location of the logic for the event cannot be evaluated. For example, if the OnOpen property of a form is set to =[Field], this error occurs because a macro or event name is expected to run when the event occurs.

  28. Mikei

    Dan,
    Appreciate all the work you have done to share your knowledge of and how-to’s for Access with all of us.
    Was able to solve my co-worker’s challenge of wanting to scroll through a long single unbounded main form that had multiple subforms stacked vertically.

    I had her add to the right side of the main form a long vertical text box that stretched the height of the detail section and to fill the text box with repeating text bounded by double quotes.

    Then I showed her how to set the text box’s Back, Border and Fore Color to the same color of the main form Back Color and also set the Back Style of the text box to Transparent. Essentially to make the text box invisible.

    To scroll up an down her long form, all she had to do was click within the text box, keep the cursor there and use the mouse wheel. Did not have to use any code for the form’s mousewheel event!

    Again, appreciate all your contributions to the Access and Excel programming community!

  29. Stephen Barber

    Great work Daniel – thanks! Someone asked this earlier but I didn’t see a reply: Is there a way to get rid of the chime sound when you scroll all the way to the top or bottom?

  30. Eduard Gasparyan

    Everything works well. But, for some reason, when scrolling the text in the field, when reaching the ends of the scroll, a clicking sound is heard. Please tell me how to remove it. Thanks.

  31. Dan Jackson

    Thank You!

    As Mentioned Above, anyone using x64 Installations need to replace the erroneous code with

    Public Declare PtrSafe Function apiGetFocus Lib “user32” () As LongPtr
    Public Declare PtrSafe Function SendMessage Lib “user32” Alias “SendMessageA” _
    (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr

    Much Appreciated

  32. Linnea Chapman

    Ok so I got the scroll in text box to work however my form also has a scroll bar so now if I’m in my selected text box (I have multiple textboxes on one form) the text box and the form both scroll at the same time. How do I make it only scroll on the box or form I’m in?
    Can you update the code or give me advice on this.
    Absolutely amazing code thanks!