Scroll Wheel Rich Text
By Richard Rost
20 days ago
Fixing Scroll Wheel Issues in an Access Rich Text Box
In this Microsoft Access tutorial, we will talk about why the mouse scroll wheel stops working in rich text boxes and what you can do to work around this issue. I will show you how to use VBA and the SendKeys function to simulate scrolling, explain how to identify when the notes field is active, and demonstrate how to adjust the scroll speed with a loop. We will also discuss some of the quirks of working with rich text controls in a continuous form.
Miles from Palo Alto, California (a Platinum Member) asks: I watched your video on using the mouse scroll wheel in continuous forms, and it works great with a regular text box in the footer. But when I switched that text box to rich text, the scroll wheel stopped working. Is there a way to fix that so I can still scroll through my notes?
Members
There is no extended cut, but here is the file download:
Silver Members and up get access to view Extended Cut videos, when available. Gold Members can download the files from class plus get access to the Code Vault. If you're not a member, Join Today!
Prerequisites
Recommended Courses
Keywords
TechHelp Access, scroll wheel not working in rich text box, continuous forms scroll issue, SendKeys up down arrows, notes field scroll wheel, Mouse Wheel event, GotFocus event code, LostFocus event, rich text scroll workaround, Screen.ActiveControl, For Next loop scrolling
Transcript
Welcome to another TechHelp video brought to you by AccessLearningZone.com. I am your instructor, Richard Rost.
Today, we are going to talk about why your scroll wheel stops working in a text box if that text box is a rich text box. What does that mean? Well, let's take a look.
Today's question comes from Miles in Palo Alto, California, one of my platinum members. Miles says, I watched your video on using the mouse scroll wheel in a continuous form or in continuous forms. It works great with the regular text box in the footer, but when I switched that text box to a rich text, the scroll wheel stopped working. Is there a way to fix that so I could still scroll through my notes?
Yes, that is a little quirk with Access. The trick that I show in the previous video works fine if you have normal text, but if you switch it to rich text, it stops working. I am going to show you how to fix that, how to get around it. Not fix it.
First, this is a developer-level video. What does that mean? That means if you have not done any VBA before, go start here. This is about 20 minutes long. It will teach you everything you need to know to get started programming in VBA. Today's VBA is not too complicated, but we do need to know some things that you should learn first.
Obviously, go watch my original video, the scroll wheel in continuous forms video. Specifically, in part two, I show you the trick that I am going to do first today. Then we are going to see how to fix that trick.
I am not a huge fan of SendKeys, especially if you are trying to automate stuff, but SendKeys is what we are going to use to fix this problem today. Go watch this so you know what SendKeys is. It is one of those good enough sometimes functions where it is not the best, but sometimes it will get you out of a tight jam.
Some other stuff you will need: of course, you will need to know how to use If Then statements. We are going to use Screen.ActiveControl. Optionally, I might throw in a For Next loop in there too. So we might get to that. These are all free videos. They are on my YouTube channel and on my website. Go watch all of these and then come on back.
As a brief recap, the problem we have is we have a continuous form, the scroll wheel works fine. If we throw a notes field down here because we have a notes field for our customers, go to form design, add existing fields, find the notes field, drag, drop, and put it right here. Go to that label.
These are the notes for the customer. Save. Now, since they are in the form footer, the notes you see here are the notes for the customer that you are on up top. I love doing this. But if you click down here and scroll, notice, it does scroll the box, but it is also scrolling the form.
The simple trick that we talked about in part two of the scroll wheel in continuous forms is to simply turn off the form's scroll bar when this guy gets the focus, and then turn it back on again when you leave the focus. Very easy, two lines of code.
Open up the properties. Go to Events for this box. GotFocus is right there, and in here we say Me.ScrollBars = 0. Me is the form, so turn the scroll bars off or none. In the LostFocus event, we are going to say Me.ScrollBars = 2, which is vertical only. Yes, there are Access constants for that, VB ScrollBar or something, you can look it up, but I just use the numbers. I think one is horizontal only, and I think one of those is both, but regardless of that, save it.
Come back out here, close it, open it. Now if I am up here, I have a scroll bar. If I click down here, it turns off the form scroll bar, and now I can continue to scroll inside the box. That is the solution from the previous video.
Now, if I turn that into rich text, first we will do it in a table. Design view, always do it in a table first. You want to make sure your table is also set to rich text, otherwise, you might get some weird formatting.
Set that to rich text here for the notes field, save it. Then come back to your list form. You have to do it in any other form you might have it as well, otherwise, you will see weird characters. You will see HTML characters.
Open up this guy, go to Data. You would think it would be under Format, but it is under Data. Set that to rich text. Save it.
Now you can come in here and do fancy stuff like select text. You get this thing; you can set it to red and bold and whatever. But notice, I am scrolling with the wheel and nothing is happening. You cannot see it, it is off camera, but trust me, my fingers are rolling up and down on the button.
Here is a visual. I am rolling up and down on the button. I am doing the thing, but it is not working. If I come back up here and click, yes, this still works. Ignore the beeping. Every now and then, a beep. So I use this scroll wheel. But if I click in here, no bueno.
How do we fix this? This is a case where it is just a quirk with how Access behaves. The way we are going to fix it is by simulating SendKeys with up and down arrows. If you hit the keyboard, if I am hitting the keyboard right now, up, down, see, it scrolls. So that is what we are going to simulate with code.
There is no other easy way to do this. Yes, there are Windows API calls and all kinds of crazy stuff you can do to get around this, but this is a nice, simple, three-line solution that will work.
I am all about easy solutions. Now, leave the GotFocus code that we put in there before because you still want to disable that behavior when you click on and off the box.
But in here, what we want to do is say, if the focus is on the notes field, then we are going to SendKeys up and down arrows.
Where do we put that code? We are going to look for the form properties, go to Events, and find the Mouse Wheel event. You might not know there is an On Mouse Wheel event. Go in here.
Now we get ByVal Pages As Boolean, and Count As Long. Do not worry about Page for the purposes of this video, but the Count is what we care about. Now, Count is either going to be negative or positive. It is negative if you are scrolling up and positive if you are scrolling down with the wheel. That value is sent into this function.
We are going to first check to see if the user is on the notes field. We do that with Screen.ActiveControl. So if Screen.ActiveControl.Name, if the name of the active control is notes (in my case, that is the name of the text box), then do something.
Now, if Count is less than zero, then SendKeys the up arrow. The up arrow looks like this: curly brace, up, close curly brace. Otherwise, we are going to do the opposite, we are going to SendKeys down.
The mouse wheel event is fired, check to see if we are on the notes field. If the count is less than zero, SendKeys up. Otherwise, SendKeys down. It is that simple.
Save it. Debug, Compile once in a while. Close it. Close it. Open it.
Clicking up here, scroll up and down. It is not sending the keys because we are not in the notes field. If I click down here, look at that, it is sending keys. Look at that.
You do not need any error handling at all because SendKeys, the down arrow, cannot by itself just go beyond the bounds. You do not have to worry about going too far up or too far down. Nice and easy. Not a bad solution.
If you click back up here, all that code takes back over again. I wish I knew how to turn that beep off, but I do not. If anyone knows how to turn that beep off, let me know. Post in the comments.
One other thing, and I did this in my database, I tweaked it: If you have a big text box, sometimes I have a very large text box in a very small scrollable area. If it is like this, when you come in here and click, well, that is a very short one. Let me pick someone who has got it. Here is a long one. You click and it could take a while to get down to the bottom. You go back up, up, up, up, up.
You might want to make it so that for each one of those, it SendKeys more than one up or down. You can do that with a For loop.
We come in here and we will say Dim X As Long, and inside here, we will just say For X = 1 To however many you want to do, three, four, five, whatever. Then put that whole thing inside of a loop. Now each time that fires it is going to go three spaces up or three spaces down. You just have to make it for whatever size your box is, whatever you are comfortable with.
Now, if I do it, click, now it goes three at a time, so it is much more of a larger scrolling there.
There are a million other things you can do. There are a lot of different ways to solve this. This is nice, it is simple, it is an easy solution. You could play tricks with the SelStart. There are Windows API calls you can use, but this works. I am all about nice easy solutions.
That is it. I am going to help video for today. Post in the comments. Let me know what you thought. I love hearing your feedback. And if you have got a better way to do this, let me know. In fact, that solution last time, part two, that was a user recommendation. I am like, wow, that is amazing. I love it when you guys teach me stuff. That is really cool.
Wait, someone's beaming in. Great. Now I have a transporter pad full of tribbles I have to deal with, but that is going to be your TechHelp video for today.
I hope you learned something. Live long and prosper, my friends. I will see you next time.
TOPICS: Explaining the scroll wheel issue in rich text boxes Demonstrating how scroll bars behave with plain text boxes Adding a notes field to a continuous form in Access Disabling and enabling form scroll bars using GotFocus and LostFocus events Changing a text field and control to rich text format Simulating scroll wheel functionality in a rich text box using SendKeys Using the Mouse Wheel event to trigger custom scrolling Determining the active control with Screen.ActiveControl Handling the Count parameter in On Mouse Wheel event Sending up or down arrow keystrokes based on scroll direction Using a For loop to increase scroll speed with multiple SendKeys
COMMERCIAL: In today's video, we are going to learn why your mouse scroll wheel stops working in an Access rich text box and, more importantly, how to get around this frustrating quirk. I will show you the step-by-step solution using simple VBA code and the SendKeys function to restore scrolling, even with rich text fields. You will see how to set up the necessary events, work with ActiveControl, and even use loops for a smoother scrolling experience in bigger text boxes. If you want an easy fix to this annoying issue, you will not want to miss this one. You will find the complete video on my YouTube channel and on my website at the link shown. Live long and prosper my friends.
Quiz
Q1. What is the main issue discussed in the video? A. The scroll wheel does not work in a rich text box in Access forms B. Rich text cannot be used in Access forms C. The scroll bar disappears automatically in all text boxes D. The form cannot be scrolled at all
Q2. What is the difference between a regular text box and a rich text box in Access regarding scroll wheel behavior? A. The scroll wheel works in both types by default B. The scroll wheel only works in regular text boxes, not in rich text boxes C. The scroll wheel only works in rich text boxes if it contains images D. The scroll wheel is completely disabled in both types
Q3. What previous solution was discussed for allowing scroll wheel use in a continuous form? A. Enabling form navigation buttons B. Turning off the form scroll bar when the text box gets focus and turning it back on when focus is lost C. Changing the form view to datasheet D. Increasing the width of the text box
Q4. When converting a notes field to rich text, what must you set in both the table and the form to avoid formatting issues? A. Set both to currency B. Set both to plain text C. Set both to rich text D. Set both to date/time
Q5. What method is suggested in the video to simulate scroll wheel functionality in a rich text box? A. Using Windows API calls exclusively B. Using SendKeys to send up and down arrow keystrokes C. Creating a macro for scrolling D. Increasing font size dynamically
Q6. In which form event should the SendKeys code be placed to handle scroll wheel activity? A. On Click B. Before Update C. On Mouse Wheel D. On Open
Q7. What property or object is used to determine if the notes field currently has focus? A. Me.Notes.Value B. Screen.ActiveControl.Name C. Me.ActiveForm D. Application.CurrentObject
Q8. In the On Mouse Wheel event, what does the Count parameter indicate? A. The font size in the text box B. The number of records in the form C. The direction of the scroll (negative for up, positive for down) D. The number of controls on the form
Q9. What is a potential way to increase the scroll 'speed' when using SendKeys in the solution? A. Use a Select Case statement B. Change the Data Type of the notes field C. Wrap the SendKeys statement in a For loop to send multiple keystrokes D. Enable both horizontal and vertical scroll bars
Q10. What is a limitation or potential downside of using SendKeys as mentioned in the video? A. It only works with tables, not forms B. It sometimes causes Access to crash C. It is not always the best or most robust solution but is 'good enough' for some cases D. SendKeys does not work with mouse events
Q11. What happens if you forget to set the notes field property to rich text in both the table and the form? A. The field will become read-only B. You may see weird HTML formatting or characters C. The text will be hidden from view D. It will increase database size significantly
Q12. What optional programming construct did the video mention for advanced scrolling control? A. Do While loop B. For Next loop C. With statement D. Select Case block
Q13. Why does the video recommend leaving the previous GotFocus/LostFocus scroll bar code in place after implementing the SendKeys workaround? A. To retain the default form color B. To continue disabling unwanted scroll bar behavior when switching focus C. To maintain the sorting order in the data D. To enable data validation
Q14. What is a recommended way to learn the prerequisite skills for this solution if you are new to Access VBA? A. Watch a 20-minute beginner VBA video suggested by the instructor B. Memorize the entire Access help file C. Only use macros, never VBA D. Study SQL exclusively
Answers: 1-A; 2-B; 3-B; 4-C; 5-B; 6-C; 7-B; 8-C; 9-C; 10-C; 11-B; 12-B; 13-B; 14-A
DISCLAIMER: Quiz questions are AI generated. If you find any that are wrong, don't make sense, or aren't related to the video topic at hand, then please post a comment and let me know. Thanks.
Summary
Today's TechHelp tutorial from Access Learning Zone focuses on a common issue encountered in Microsoft Access: why the mouse scroll wheel stops working when you're using a rich text box inside a form. Many users have found that scrolling works perfectly in a regular text box, but once that same box is switched to rich text, the scroll wheel seems to have no effect. Let me explain what's going on and how you can address it.
To set the stage, the problem tends to arise in continuous forms where you have a text box in the footer or another area displaying notes or other long-form content. When this text box uses plain text, the scroll wheel moves through the field as expected. However, once you enable rich text formatting, the wheel no longer scrolls through the content. This can be frustrating if you have long notes and need to move quickly within them.
Before diving into the solution, I want to mention that today's lesson is intended for those who have some experience with VBA programming in Access. If you are new to VBA, I recommend taking some time to learn the basics, such as writing simple If Then statements and understanding how controls and forms interact via code. There are plenty of beginner-level resources on my site and YouTube channel to get you started with VBA, as well as specific videos on topics like Scroll Wheel events and using the SendKeys function. It's worth brushing up on these concepts before tackling this issue.
Let me briefly recap the previous approach that works for standard text boxes. Normally, you can manage scrolling within a text box by temporarily disabling the form's scroll bars when the text box receives focus, and then turning them back on when the focus is lost. This can be done with some straightforward code in the GotFocus and LostFocus event handlers of the control. When you click in the text box, the form's scroll bars are hidden so the mouse wheel only scrolls the box. Once you leave the box, the scroll bars return. This method is effective for plain text boxes but unfortunately does not carry over to rich text controls.
Switching to rich text requires a bit more setup. First, ensure that the field in your underlying table is set to rich text. If not, you may encounter display issues, such as seeing raw HTML or unexpected formatting. After updating the table, configure the text box on your form to use rich text as well. This will allow for advanced formatting, but as you'll notice, the mouse scroll wheel stops working within the box. No matter what you try, the wheel no longer scrolls through the field's contents, making it inconvenient to read or edit long notes.
The workaround involves simulating keystrokes using the SendKeys function. While SendKeys is not ideal for all programming situations and has its limitations, it offers a simple and effective solution to this particular problem. The idea is to capture the Mouse Wheel event on the form and, when the active control is the rich text box, use SendKeys to simulate pressing the up or down arrow keys. This has the same effect as scrolling through the text box with the keyboard.
To set this up, you need to write code in the form's Mouse Wheel event handler. The event provides a Count parameter, which is negative when the wheel scrolls up and positive when it scrolls down. Inside this event, check if the Screen.ActiveControl is your notes box. If it is, use SendKeys to simulate the arrow keys: up if the wheel is moved up, down otherwise.
This approach is concise and avoids more complex solutions, like using Windows API calls, which are unnecessary for such a straightforward need. Maintain the GotFocus and LostFocus event handlers as before to control the form's scroll bars, but handle the scrolling action with SendKeys inside the Mouse Wheel event.
You do not need any special error handling for this application since sending up and down key presses will not generate problems even if you try to scroll beyond the boundaries of the text box. The workaround is safe and keeps things simple.
If you find that scrolling is too slow, especially in large text boxes, you can enhance the solution by sending multiple arrow key presses at a time. This can be accomplished by adding a For loop inside the Mouse Wheel event code so that each wheel action moves the view by several lines instead of just one. Adjust the loop to scroll by as many lines as you see fit for your application.
There are other potential approaches to this problem, such as manipulating the SelStart property or invoking Windows APIs, but for most applications, the SendKeys method is quick and effective. Customizing the number of simulated key presses gives you additional control over the scrolling speed.
That wraps up today's TechHelp tutorial. If you have suggestions for improvements or know another way to handle this scrolling issue, I encourage you to share your insights. I always appreciate feedback and new ideas from my students.
You can find a complete video tutorial with step-by-step instructions on everything discussed here on my website at the link below. Live long and prosper, my friends.
Topic List
Explaining the scroll wheel issue in rich text boxes Demonstrating how scroll bars behave with plain text boxes Adding a notes field to a continuous form in Access Disabling and enabling form scroll bars using GotFocus and LostFocus events Changing a text field and control to rich text format Simulating scroll wheel functionality in a rich text box using SendKeys Using the Mouse Wheel event to trigger custom scrolling Determining the active control with Screen.ActiveControl Handling the Count parameter in On Mouse Wheel event Sending up or down arrow keystrokes based on scroll direction Using a For loop to increase scroll speed with multiple SendKeys
Article
If you have ever tried to use the mouse scroll wheel inside a rich text box in Microsoft Access and found that it does not work, you are not alone. This is a common quirk in Access, particularly when working with continuous forms and rich text fields. Let me walk you through why this happens and show you a straightforward solution using VBA.
Imagine you have a continuous form that displays customer data. You have a notes field where you want to store additional information about each customer. By adding this notes field as a text box in the form's footer, you can show and edit the current customer's notes no matter which record is selected. Normally, when this notes text box is set to plain text, scrolling inside the box works fine, especially if you use the handy trick of disabling the form's scroll bar when the notes box has focus. This technique stops the entire form from scrolling when the user is trying to scroll only inside the notes text box.
You can do this with simple VBA. Open your form, go to the properties of the notes text box, and set up two events. In the GotFocus event, use this code:
Me.ScrollBars = 0
This disables the scroll bars on the form itself when the text box receives focus. In the LostFocus event, use this code:
Me.ScrollBars = 2
This re-enables the vertical scroll bar when the text box loses focus. With these two lines in place, clicking on the notes box allows you to scroll through the text field without also scrolling the whole form.
However, things change if you decide to upgrade your notes field to use rich text formatting, so you can include bold, colored, or formatted text. To do this, go to your table in Design View, select the notes field, and set its Text Format property to Rich Text. Then, in your form, select the corresponding notes text box, go to the Data tab, and set its Text Format property to Rich Text as well. Now you can apply formatting to your text, but there is a side effect: the mouse scroll wheel no longer scrolls through the contents of the notes box. Instead, it has no effect, and the text inside remains static no matter how much you try to scroll with the mouse wheel. This can be quite frustrating if you have a lot of notes to look through.
Why does this happen? It is simply how Access handles rich text boxes. The scroll wheel is not hooked up by default. But there is a workaround using VBA that simulates the keyboard's arrow keys (up and down) whenever the mouse wheel is used, giving you the ability to scroll through the box as you would with the arrow keys.
To set this up, you will use the Mouse Wheel event on your form. Go to the form's properties, select the Events tab, and find the On Mouse Wheel event. Edit this event and add the following VBA code (replace 'notes' with the actual name of your rich text box if it is different):
Private Sub Form_MouseWheel(ByVal Page As Boolean, ByVal Count As Long) If Screen.ActiveControl.Name = "notes" Then If Count < 0 Then SendKeys "{UP}" Else SendKeys "{DOWN}" End If End If End Sub
Let us break down how it works. When you use the mouse wheel, the MouseWheel event fires. The Count parameter tells you if you are scrolling up (negative value) or down (positive value). The code first checks if the active control is the notes text box. If it is, and you are scrolling up, it sends an up arrow keystroke to move the cursor up in the box. If you are scrolling down, it sends a down arrow keystroke. This mimics the effect of scrolling in a plain text box, surprising as it may seem. The result is that moving the mouse wheel will scroll the box–even in rich text mode.
You can further customize this. For example, if your notes field contains a lot of text and the scroll area is very small, you might want faster scrolling. You can accomplish this by using a For loop to send multiple up or down key presses each time the mouse wheel moves. For example:
Private Sub Form_MouseWheel(ByVal Page As Boolean, ByVal Count As Long) Dim X As Long If Screen.ActiveControl.Name = "notes" Then For X = 1 To 3 ' Change 3 to however many lines you want to scroll each wheel notch If Count < 0 Then SendKeys "{UP}" Else SendKeys "{DOWN}" End If Next X End If End Sub
Now, each movement of the mouse wheel will scroll three lines instead of one, making it much easier to move quickly through longer notes.
If you decide to use this approach, keep your original GotFocus and LostFocus event code as well. This ensures that the scroll bar settings on your form are still managed correctly depending on which control has the focus.
This is a practical and simple solution to a tricky problem. It does rely on the SendKeys command, which is not always the most robust method, but for this particular use case it works reliably and lets you regain scroll wheel functionality in Access rich text boxes. If you want to experiment further, you could look into more advanced solutions using Windows API calls, but for most uses, this approach gets the job done with minimal fuss.
|