Scroll Wheel & Continuous Forms 2
By Richard Rost
13 months ago
Stop Scroll Wheel from Moving Records in Forms Part 2
In this Microsoft Access tutorial, I will show you how to stop the scroll wheel from moving records in continuous forms while in the Notes field using a simple two-line VBA solution. We will disable and re-enable scrollbars based on the text box's focus. This is part 2.
Members
There is no extended cut, but here is the database 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, stop scroll wheel continuous forms Microsoft Access, prevent scroll wheel notes field Access, turn off scroll bars VBA Access, continuous forms scroll issue solution, scroll bars control Access VBA, fix scroll issue continuous forms, scroll wheel fix continuous forms Access, Microsoft Access tutorial continuous forms
Transcript
Welcome to another TechHelp video brought to you by AccessLearningZone.com. I'm your instructor Richard Rost. Today is part two that I wasn't even planning on making for the scroll wheel and continuous forms video. I made part one, thought that was it, but then I got a comment from one of my members who had a much simpler solution to what I showed you in part one.
So if you haven't watched part one yet, I show you how to make a subform down here, which will then allow you to scroll the mouse wheel up and down here without this part scrolling. This is okay, and I'm still going to leave this video up because this is a decent method. It's an expert method, which means it doesn't involve any programming.
If you're one of those people that doesn't want to use VBA anymore, this method is perfectly fine. In the extended cut, I showed the members how to automatically have this subform resize based on the size of the subform object. That was pretty cool too. They are all good tips to have.
Then I got a comment from Damien, one of my silver members. He says you can also fix this with two lines of VBA. I'm got focus and an on lost focus. It's me.scrollbars, which basically says you're turning the scrollbars off on the parent form, on the continuous form, when the text box gets the focus.
I looked at it and I was like, no, it can't be that simple. This is genius. I love this. I love, love, love when you guys teach me something. Of course, I had to try it immediately. Let me walk you through it.
Of course, real quick, this is a developer lesson. If you've never done any VBA programming before, go watch this video. It will get you started in about 20 minutes. But today's really simple. It's just two lines of code.
All right. So here I am in the TechHelp free template. This is a free database you can download from the website if you want to. We can start with yesterday's database too. But I'm just going to go right into the customer list. We put a note field down here on the bottom.
I stole that note field from the customer form, which already has a notes field. We'll just copy that and come down to here, go to design view, paste it in here. Okay. All right. Now we'll save this and then come back into it.
The problem we have is you can scroll with the wheel up here. But if you click down here and scroll, it also scrolls the records up top, which is undesirable. In part one, I showed you that you can just make this a subform and that gets rid of that problem.
Here's Damien's genius idea. All you do is you turn off the scroll bar when this field gets the focus. The focus is wherever you're sitting right now. Last name is focus, right? Customer ID has focus. When the notes field gets the focus, turn off the scroll bar.
Go into the notes field, go to events, and find on got focus. There's got focus and lost focus. Go to got focus. In here, we're going to say me. Now remember, me represents the form. Me is not the control; me is the form. So me.scrollbars = 0 (0 is off).
Then we'll go to the lost focus event, which you can get right here, and type me.scrollbars = 2. Two is vertical. If memory serves, 1 is horizontal only, and I think 3 is both, but I'm not sure. Let me look it up real quick. Yeah, that's right. Zero is off, one is horizontal, two is vertical, and three is both.
Save that. Always throw in a debug compile. We can close the VBA editor, close the form, and reopen it. Now I can scroll up here. If I click down here, look at that, the scroll bar disappeared up top. Now I'm scrolling down here. If I decide I want to click back up top, I can do that again. See, isn't that nice?
You have to give the text box focus by clicking on it first for these ones. That's not a big deal. If you come over here, you also have to click up here, but I like it. It's a good solution. It's beautiful. Like I said, I love it when you guys teach me something. That's wonderful.
So that's it for today. Nice and short and simple and sweet. I wasn't planning on doing a part two, but there's your part two. Thank you, Damien, for the tip. That's going to be your TechHelp video for today. I hope you learned something. Live long and prosper, my friends. I'll see you next time.
TOPICS: Scroll wheel and continuous forms part 2 Creating a subform to manage scrolling Resizing subform based on object size Using VBA to control scrollbars Setting up 'On Got Focus' and 'On Lost Focus' events Disabling scrollbars on focus Enabling scrollbars on lost focus Debugging and compiling VBA code Testing scroll behavior in forms
COMMERCIAL: In today's video, I'm going to show you a quick, two-line VBA solution to fix an issue with scroll bars in continuous forms. If you haven't seen part one, don't worry - I'll explain everything. We start by adding a note field to the customer list, then solve the undesired scrolling problem with a subform. But thanks to a tip from one of my members, you'll learn to control scroll bars using 'Got Focus' and 'Lost Focus' events. It's a simple yet effective trick to make your Access forms more user-friendly. You'll 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 primary problem addressed in part two of the tutorial? A. Creating a new subform B. Adjusting the size of a subform C. Stopping the mouse wheel from affecting multiple areas D. Adding new fields to a form
Q2. What was Damien's suggested solution for the scrolling issue? A. Use a new subform with custom properties B. Disable the scrollbars using VBA code C. Increase the size of the text box D. Rearrange the layout of the form
Q3. What does the VBA code `me.scrollbars = 0` do when the notes field gets focus? A. Turns off horizontal scrollbars B. Turns off vertical scrollbars C. Turns off all scrollbars D. Turns on both scrollbars
Q4. In the `on got focus` event for the notes field, what does the `me` keyword represent? A. The text box control B. The parent form C. The subform D. The entire database
Q5. What event is used to turn the scrollbars back on after losing focus on the notes field? A. on click B. on load C. lost focus D. key press
Q6. According to the tutorial, what value should `me.scrollbars` be set to for vertical scrollbars only? A. 0 B. 1 C. 2 D. 3
Q7. Which method did Richard initially show to solve the scrolling issue? A. Adjusting database properties B. Using a subform C. Modifying the layout of the main form D. Adding a new scroll attribute to the form
Q8. Why does Richard appreciate suggestions and tips from his community of members? A. It saves him time in form development B. It enhances the quality of his tutorials C. It eliminates the need for programming D. It allows him to stop making videos
Q9. What action must be taken to make the scroll bar disappear up top when clicking on the notes field? A. Click on the customer ID field first B. Click directly on the notes field C. Use a keyboard shortcut D. Open a new form
Q10. How does Richard describe his reaction to Damien's proposed solution? A. He was skeptical at first B. He immediately disliked the idea C. He thought it was irrelevant D. He had already thought of it
Answers: 1-C; 2-B; 3-C; 4-B; 5-C; 6-C; 7-B; 8-B; 9-B; 10-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 explores a simpler solution to handling scroll wheel functionality in continuous forms, shared by one of our members. I'm your instructor, Richard Rost, and this is an unplanned part two following up on my previous video. In the first part, I demonstrated how to create a subform so you can scroll the mouse wheel without affecting the main form.
If you missed part one, I showed how to set up a subform to manage scrolling independently from the main form. This method is straightforward and great for those not keen on using VBA. I even included tips on resizing the subform automatically, which I shared with my members. It's a valid method and worth knowing.
Then, Damien, one of my silver members, suggested an even simpler approach using just two lines of VBA code. This tip involves using the got focus and lost focus events to manage scrollbars on the parent form. Essentially, it disables the scrollbars when the text box gains focus and re-enables them when it loses focus.
I love learning from you all, so I had to try out Damien's method immediately. For those new to VBA, there's a beginner's tutorial on my website that will get you up to speed in about 20 minutes. Today, however, focuses on a very straightforward solution involving minimal code.
Let's use the TechHelp free template, which you can download from my website. We're going to modify the customer list form by adding a notes field at the bottom, similar to the notes field on the customer form. Copy the existing notes field and paste it into the design view of the customer list form.
The issue we face is that scrolling the wheel in the notes field also scrolls the records in the customer list, which is not ideal. In part one, I showed you that making the notes field a subform resolves this issue. Now, with Damien's approach, we can solve it with two lines of code.
To implement this, we simply turn off the scroll bar when the notes field gains focus. The focus indicates the current active control, such as the last name field or customer ID. When the notes field gets the focus, we'll disable the scroll bar for the parent form.
In the notes field's properties, go to the events tab and find the got focus event. Here, you'll need to update the form by setting the scrollbars property to 0 (off). Then, for the lost focus event, set the scrollbars property back to 2 (vertical).
Remember, "me" refers to the form and not the control. The values for the scrollbar property are 0 (off), 1 (horizontal), 2 (vertical), and 3 (both). After saving and debugging the code, close the VBA editor, and reopen the form.
You'll now notice that scrolling works independently in the notes field without affecting the main form's records. Clicking back on the main form's fields reactivates the scroll bar. This solution requires clicking to grant focus but offers a clean fix.
Thank you, Damien, for this efficient tip. I hope today's tutorial has been helpful. For a complete video tutorial with step-by-step instructions, visit my website at the link below. Live long and prosper, my friends.
Topic List
Scroll wheel and continuous forms part 2 Creating a subform to manage scrolling Resizing subform based on object size Using VBA to control scrollbars Setting up 'On Got Focus' and 'On Lost Focus' events Disabling scrollbars on focus Enabling scrollbars on lost focus Debugging and compiling VBA code Testing scroll behavior in forms
|