Subform Goto First Field
By Richard Rost
14 months ago
Navigate Form Sections & Set Focus in Access Subform In this Microsoft Access tutorial, you will learn how to navigate form sections and set focus on the first field of the first record in a subform. We'll address a common issue where the tab order skips the header section, providing both beginner keyboard shortcut solutions and a simple programming method using VBA to customize form navigation. Antonio from Lytle, Texas (a Gold Member) asks: I have created a parent form that includes a subform. The subform contains fields in both its header and detail sections. When I tab from the parent form to the subform, it skips the header and directly navigates to the detail section of the subform. I'd like the tab order to be: Parent Form, Subform Header, and then Subform Detail. Can anyone help me achieve this? MembersThere 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!
PrerequisitesLinksRecommended CoursesUp Next
Keywords TechHelp Access, Microsoft Access subform navigation, Access set focus first field, Access subform header tab order, VBA go to record, Access subform tab solution, Access parent form navigation, Access F6 keyboard shortcut, Access on enter event, Access beginner form navigation tutorial
Transcript
Today we're going to talk about moving between the different parts of a form with a subform. You might have a header and a footer and a bunch of other sections. Maybe the tab order isn't going exactly where you want it to go when you press that tab key. So we're going to talk about how to navigate form sections and set the focus on the first field of the first record in a subform. Even if you left that subform previously and you weren't there, I'll explain what all this means in a minute.
This is going to be both a beginner and a developer video because I'm going to start off by showing you some keyboard shortcuts you can use, which is just a training issue to learn how to navigate around using the keyboard. Then I'm going to teach you a developer means with a couple of lines of code so that if you don't feel like remembering all these keyboard shortcuts, you don't have to. You can just press the tab key and it'll go where you want it to go.
This is a question I've gotten a couple of times in different forms, but today in the forums and Antonio from Lytle, Texas. I hope I pronounced that correctly. One of my gold members posted this in the forums: you said, I've created a parent form that includes the subform when the subform contains fields in both its header and detail sections. When I tab from the parent form to the subform, it skips the header and navigates directly to the detail section of the subform. Yeah, that's kind of how it's designed. I'd like the tab order to be parent form, subform header, subform detail. Can anyone help me achieve this?
Yes, I think we can help you. And I know a couple of the guys already posted answers in the forum. There are lots of different ways to handle this. I'm going to show you two.
Before we get started, if you are a beginner and you don't care about the VB stuff, I'm going to show you a little bit later. Make sure you understand this stuff: tab order, tab stop, and tab cycle. I cover this stuff in my beginner lessons, but if you've not learned that stuff, go watch this video first and then come on back.
I'm also going to be using my TechHelp free template today. This is the video where I cover building the order entry system that I'm going to use for this example because it has a subform. These are free videos. They're on my website. They're on my YouTube channel. Go watch those and come on back.
Okay, so here I am in the TechHelp free template. This is a free database. You can download it from my website. I've got a customer form. Customers can have orders. This is a parent form with a subform in it. Now normally when you tab, tab, tab, tab, tab, tab, tab, it jumps into the subform in the first field. Now I've gotten this question in a lot of other ways. Sometimes people ask, okay, if I tab, tab, tab, tab, tab, down to here, okay, and then I come back up top to the parent form and then I tab, tab, tab, tab, tab, it returns me right to that spot that I was down here, and some people don't like that.
Right, because sometimes you may go to a new record, and usually it'll jump you back to the first one, not always. Okay, but sometimes people want to say, okay, if I'm up here and I tab, tab, tab, I want it to always return me back up to the first field. So that's another version of this question. But what Antonio is saying is he's got a header section in here. Now I have a header section. It's right there, but I just have labels in it.
Okay, so let's make this header section a little bigger, and I'm going to move my notes field up into the header. So that's going to act as like the first field. Okay, so instead of being in the footer, the notes are now in the header. And remember, if a field is in the form header or the form footer, if it's a bound field, it means it's bound to a field in your table. That means it's going to be bound to whatever record you're on in here. Right, I cover this in my invoicing video.
So if I come in here, this is the notes for the hyper drive. This is the notes. These are the notes for the phaser bank. See how that changes as I move from record to record. Right, life support notes. Okay.
Now here's the problem that Antonio is running into. You go up here, tab, tab, tab. It's on the "Is Paid" field over here in the corner. I know, not great tab order. Tab, tab. See, it comes right back down here because that's where I left off. If you're on a new record, let's go over to here. And I'm up top here, right, tab, tab, tab, tab, tab. This is right back down on the hard drive again.
So what we want to do is we want it to come here to the product notes field here, right, the notes field. All right, so first, the beginner solution. How do we do this with the keyboard with no programming required? Well, we can use the F6 key to jump between the different sections in Access. It's going to include the form view and the Access interface. It's also not the best solution, but it's the free and cheap one that requires no programming.
So if I'm up here in the parent detail section and I hit F6, it brings me down to the header of the subform. Okay, hit F6 again and now you're in the detail section of the subform, hit it again, and now you're in the footer of the subform. All right, three different sections in the subform that I have here. Now, here's where it gets tricky. From here, if you hit F6, it puts you over in the navigation pane. And if you hit F6 again, now you're up here. And if you hit F6 again, now you're down here. So the F6 isn't really the best solution.
But if like if you're here and you want to make sure you go down to the subform, right, tab, tab, tab, and you're in, okay, you're in the wrong spot, you can hit F6 and go to the detail section or shift F6 to go backwards. All right, so you've got F6, F6, shift F6, shift F6, and so on. But if you hit it too many times, you're going to end up up here. So that's not the best solution.
So let's see what the programming solution is. Now, if you've never done any VBA programming before, don't panic. It's not hard. We literally need two lines of code to do what we want to do today. And there are a couple of extra little things I might show you, but just it's not hard.
All right, so go watch this video first. It's not scary. It's about 20 minutes long. It'll teach you everything you need to know to get started. It's free. It's on my website, on my YouTube channel. Go watch this. All right.
Now, here's the logic of what we want to do. Okay. When I go from the parent form into the subform, okay, when I enter the subform, usually using the keyboard, then I want to go to the notes field. And I also want to go to the first record because I don't want to end up in the notes field for, you know, the third or fourth record from down here. Right. So if I come up here and I tab, tab, tab, tab, I want it to go straight here on the first record. That's what I want to do. Okay.
So we need two lines of code to do this. We just have to know where to put them. So let's go into design view. Let's go to the subform control. Remember, there's a box around the entire subform. That is the subform control itself. And if you double click on that box, it'll bring up the property sheet. And make sure it says property sheet subform subreport. You don't want to be inside the subform because you're going to be on one of these controls in here. It'll say text box or section.
No, I want to be on the subform control itself. All right. So make sure you're on that box. And it'll say subform subreport. Go to the event tab. There's two events in here. Okay. This is when the subform itself gets the focus. All right. If you tab into it, it's going to get the focus. So the on enter event is what we want. So click on dot dot dot that'll bring up your code builder.
All right. The first thing I'm going to do is I want to go to the first record when I tab into the subform. We're going to use the go to record command do command dot go to record. There it is. Now you can ignore, you can use the defaults for these first two things. Right. The object name, the object type. That's fine. Use the defaults. So comma, comma. And then the record we want to go to is AC first the first record in the subform. Okay.
And now the next thing I want to do is I want to put the focus on the field that I want to be on, which in this case is the notes. There are a couple of ways you can do it. You can use set focus. I'm going to use do command dot go to control. And then I want to go to the notes field. That's that simple. It's two lines of code.
Okay. All right. Save it. Always throw in a debug compile once in a while. All right. Come back over here. And now watch this tab tab tab tab tab. You can briefly see it flashes down here because it goes to the product thing, but then our code kicks in and it moves it right up here. Right. So I'll come up. Let's do one more time. Tab tab tab tab tab tab. And you're right where you want to be.
Now the next problem of course is if I hit tab here, tab tab tab tab tab, it doesn't jump between the different sections. So I can hit F6 and go down there. If I want to then tab tab tab tab tab. Or if you want to you can also say okay if I'm in here and the user hits tab, I want to jump down to the first record of the subform. How do we do that? Well that's a little more complicated. But again it's still only like three lines of code. You just have to know where to put it.
We basically have to intercept the user's keystroke and say if they're in this field and they hit the tab key, then move down to the product name field. And I'll show you how to do that. In tomorrow's class. So tune in tomorrow same bat time same bat channel. Or if you're a member you're going to watch it right now because that's one of the benefits of membership.
While you're waiting for tomorrow's video if you want to learn more about moving around in a form using go to record and go to control, I have this video go watch this is free. And of course if you like learning with me and you want to learn more about this VBA programming thing, what is this newfangled stuff the kids are doing. Well I got tons and tons of developer lessons on my website. I take you through beginner all the way to advance developer programming.
There's so much to cover there's lots of it. I've got hours and hours and hours of lessons on my website. Don't let it intimidate you. I take you through it step by step. We go with everything from multi select list boxes to getting stuff off the web to records sets to inventory. You just you name it. I've been doing this for 20 years. And this is the culmination of most of my knowledge.
So check it out on the website. There's the link right there. Tune into my part two. And that is going to be your TechHelp video for today. I hope you learned something. Live long and prosper my friends. I'll see you tomorrow for part two.
TOPICS: Navigating form sections in Access Setting focus on first field in a subform Changing tab order with VBA Keyboard shortcuts for form navigation Using F6 key to navigate sections Programming solution for tab order VBA code: do command go to record VBA code: do command go to control Subform control event properties On enter event for subform Debugging and compiling VBA code
COMMERCIAL: In today's video, we're going to learn how to navigate form sections in Access when you have a subform that includes both header and detail sections. Ever wonder why your tab order skips the header and jumps straight to the detail section? We'll show you how to set the focus correctly using both keyboard shortcuts and some simple VBA code. First, I'll demonstrate some handy keyboard techniques, then I'll show you how to programmatically ensure tabs go exactly where you want them. Whether you're a beginner or a developer, there's something for you here. 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 focus of this video tutorial? A. Creating a new parent form and subform in Access B. Navigating between different sections of a form with a subform C. Designing an interface for data entry D. Setting up database relationships between forms
Q2. Which keyboard shortcut can be used to navigate between different sections in Access? A. F4 B. F5 C. F6 D. Shift + F4
Q3. In the context of this tutorial, what programming language is suggested for automating navigation between form sections? A. JavaScript B. Python C. SQL D. VBA (Visual Basic for Applications)
Q4. When setting focus in a subform using VBA, which command is used to navigate to a specific record? A. Go to Item B. DoCmd.GoToRecord C. Form.Navigate D. Record.GoToFirst
Q5. Why might someone prefer to use VBA code rather than keyboard shortcuts for form navigation? A. It allows navigation without overriding default functions B. It requires less familiarity with the software C. It ensures consistent navigation behavior tailored to user preferences D. It is faster to implement than pressing keys
Q6. If a user wants the tab order to go to a subform's header before its detail section, what is the programming event called that they should utilize? A. OnClick B. OnFocus C. OnEnter D. OnLoad
Q7. According to the tutorial, what happens if you use the F6 key too many times? A. You will return to the parent form B. You will navigate to the navigation pane C. You will be taken to the form footer D. You will exit Access
Answers: 1-B; 2-C; 3-D; 4-B; 5-C; 6-C; 7-B
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 navigating forms and subforms in Microsoft Access. If you're working with forms, you may have experienced issues with tabbing through different sections such as headers and footers. The tab order might not always be intuitive, especially if a subform is involved. Our discussion today will cover how to effectively navigate these sections and how to set the focus on the first field of the first record in a subform.
This tutorial caters to both beginners and developers. I'll start by introducing some useful keyboard shortcuts for navigating forms with the keyboard alone. Additionally, I will guide you through a simple method using a few lines of code for those who prefer not to rely solely on shortcuts.
Recently, one of my gold members, Antonio from Lytle, Texas, raised an interesting question in the forums. He set up a parent form with a subform containing fields in both the header and detail sections. However, when navigating from the parent form to the subform, the tab order skipped the header and went straight to the detail section. Antonio wanted the tab order to be parent form, subform header, then subform detail.
I believe I can help, and others have already offered solutions in the forum. There are several ways to handle this, but I will show you two: a beginner-level solution using keyboard navigation and a developer-level solution using VBA code.
For beginners unfamiliar with Visual Basic or programming, understanding concepts like tab order, tab stop, and tab cycle is essential. If this is new to you, I recommend watching some of my beginner lessons to grasp these foundational ideas before proceeding.
Today, I'm using the TechHelp free template, available for download on my website. This example involves a customer form with a subform for managing orders. Typically, when tabbing through the form, the process goes straight to the subform's first field. Many people have asked about maintaining a consistent starting point in the subform, regardless of previous navigation. Some prefer the focus to return to the first field of the first record each time.
Antonio's specific issue involved a header section. By default, certain fields might be located in the footer, but I moved a notes field into the header to demonstrate how bound fields operate when switching between records.
For those preferring a keyboard-only solution that involves no programming, the F6 key can be used to navigate through different sections of a form. The F6 key toggles between the detail section and the header, although it is not an ideal solution as it can also move the focus outside of the subform.
For a more robust solution involving code, we'll make use of VBA. If you're new to VBA, don't worry. This task only requires two lines of code. The main objective is to set the focus on the first record and a specific field - in our case, the notes field - as soon as we enter the subform. To implement this, you'll add simple commands in the On Enter event of the subform control.
This approach ensures that whenever you tab into the subform from the parent form, the focus is set as desired. After adding the code, when you navigate the form, you'll notice that although it briefly appears to focus on another field, it immediately switches to the notes field of the first record.
Dealing with section navigation after the initial tab is another challenge. While you can use F6 to move through various sections, if you prefer, additional code can facilitate jumping between fields as users tab through. I'll cover this advanced topic in a future lesson.
For now, if you want to learn more about moving records using commands like GoToRecord and GoToControl or explore VBA programming, I offer extensive lessons on my website, suitable for all skill levels. These cover a range of topics from basic navigation to advanced automation tasks in Microsoft Access.
Feel free to check out these resources and enhance your understanding. For those curious about the next steps, stay tuned for upcoming tutorials. For detailed, step-by-step instructions on everything discussed here, visit my website.
Live long and prosper, my friends.
Topic List
Navigating form sections in Access Setting focus on first field in a subform Changing tab order with VBA Keyboard shortcuts for form navigation Using F6 key to navigate sections Programming solution for tab order VBA code: do command go to record VBA code: do command go to control Subform control event properties On enter event for subform Debugging and compiling VBA code
|