Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Home > TechHelp > Directory > Access > SetFocus < Up To Midnight | GoToControl >
SetFocus
By Richard Rost   Richard Rost on LinkedIn Email Richard Rost   2 years ago

SetFocus Command in Access VBA for Form Navigation


 S  M  L  XL  FS  |  Slo  Reg  Fast  2x  |  Bookmark Join Now

In this Microsoft Access tutorial, you'll learn how to use the SetFocus command to enhance form control navigation with VBA programming. Discover how to guide users efficiently through forms, validate inputs like credit limits, and streamline your database interactions by skipping unnecessary fields based on previous entries.

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

Links

Recommended Courses

Learn More

FREE Access Beginner Level 1
FREE Access Quick Start in 30 Minutes
Access Level 2 for just $1

Free Templates

TechHelp Free Templates
Blank Template
Contact Management
Order Entry & Invoicing
More Access Templates

Resources

Diamond Sponsors - Information on our Sponsors
Mailing List - Get emails when new videos released
Consulting - Need help with your database
Tip Jar - Your tips are graciously accepted
Merch Store - Get your swag here!

Questions?

Please feel free to post your questions or comments below or post them in the Forums.

KeywordsSetFocus in Microsoft Access

TechHelp Access, SetFocus command, form control navigation, Microsoft Access VBA, focus management, tab order management, AfterUpdate event, customer form fields, cursor placement, GoToControl command comparison, NumChildren field adjustment, user input validation, credit limit validation

 

 

 

Comments for SetFocus
 
Age Subject From
2 yearsSetFocusKevin Robertson

 

Start a NEW Conversation
 
Only students may post on this page. Click here for more information on how you can set up an account. If you are a student, please Log On first. Non-students may only post in the Visitor Forum.
 
Subscribe
Subscribe to SetFocus
Get notifications when this page is updated
 
Intro In this video, we will take a look at the SetFocus command in Microsoft Access and how you can use it with VBA to improve your form control navigation. I will show you how to guide users to specific fields based on input validation, such as checking for missing or invalid credit limits, and how to skip or prioritize fields dynamically using events like AfterUpdate. We will also discuss editing forms in Design View, setting tab order, and handling form fields conditionally with SetFocus.
Transcript Welcome to another TechHelp fast tips video brought to you by AccessLearningZone.com. I'm your instructor Richard Rost. Today we're gonna take a look at the SetFocus command and how you can use it to improve your form control navigation in Microsoft Access. This, of course, is a developer-level video. So what does that mean? That means we're gonna be using some VBA programming. So if you've never done any VBA programming before, go watch this video. It'll get you started and teach you everything you need to know in about 20 minutes.

Okay, so the SetFocus command allows you to move the focus to a control of your choice. Right now, for example, the first name field has focus; now the last name field has focus. That's what the focus is, where the cursor's sitting. This is handy for a couple of different reasons. One, it helps you to improve navigation, and another is it assists you with validating input.

For example, let's say hypothetically that before you can put an order in for a customer, they have to have a credit limit. Let's say you always work with credit limits, and if a customer has no credit limit, or if their credit limit is negative, then you can't put an order in for them. I want the order button to say, "Hey, this customer doesn't have a credit limit" with a message box and then to help them out by putting the cursor in the credit limit text box.

That's how SetFocus works. We'll go to Design View, and I'll edit the code for my button build event by right-clicking. Before we do the open form, we'll put a little validation here. We'll say, "If IsNull credit limit or credit limit is less than or equal to zero, then we'll message box 'This customer does not have a credit limit or it's negative'."

I worked for a client whose old database wasn't very flexible. If the customer didn't have credit and they didn't want to leave it at zero, meaning that they weren't sure if they had credit or not, they would put it at negative one, which indicated that yes, we know this customer has bad credit. Whereas the default for that field was zero, which meant they might not have put a credit app in anyway. I digress.

So now, at this point, you've notified the user, "Hey, the customer doesn't have a credit limit or it's negative." What do you do? Well, we're gonna say, "CreditLimit.SetFocus." All these things after the dot menu are methods or properties. A method is where you're gonna do something like SetFocus or you can see there's a SizeToFit option, whereas those other things are properties of the text box, like ShowDatePicker, meaning do I show the date picker, that kind of stuff? We're focused on SetFocus right now.

Okay, now you could either Exit Sub here or make it an Else. I choose to Exit Sub because, at this point, we know we want to get out of here. Whereas if I make this an Else and then do Command OpenForm, you might forget that it's gotta exit right here if you add stuff later on. So I like the Exit Sub here.

Debug, compile once in a while, come back out here, we're gonna close everything down, save changes, yes, and open it back up again. Now I'm gonna hit orders, and it says, "Oh, the customer does not have a credit limit or it's negative." Hit okay, and SetFocus puts the cursor right there, making it easier for the user to type something in.

Okay, another use might be to aid in navigation on the form. Let's say you've got different options that may or may not be filled in depending on the user's preference. Let's say in addition to family size, we've got a field called number of children. We'll add it to the table, CustomerT Design View. I'll add a field here called NumChildren. We'll make that a number, right? We'll make the default value zero. That's fine.

Go to the customer form and let's add that field in here. Copy, paste. We'll stick it right under family size, right? We'll call this NumChildren. And we'll make the control source NumChildren. That means that's where it's getting and saving its data. We're also gonna copy that and paste it in the name so the text box's name is the same as the control source. I like to do that in most cases. Also, let's put it in the tab order in the right spot. I want it to tab after family size right to NumChildren. So we're gonna go to Form Design, Tab Order. We're gonna find NumChildren and slide it up under family size, just like that. And I got videos on all this stuff. If you don't know what I'm doing right now with the tab order, I'll put links to it down below.

All right, so let's save it, close it, and open it back up again. Now here I am in family size. If I type in five, you might assume that they have three or maybe four children, you don't know. But let's say I type in one. Well, you know, if I'm obviously dealing with adults, then you know the number of children has got to be zero. So in this case, we can use SetFocus to just skip by that and tab straight to CustomerSince.

Now I know this seems trivial right now, but I've dealt with clients before who had some pretty complicated forms that their people had to fill out all day long. It was very, very handy for them to be able to skip fields based on what was entered in previous data. Like if you're doing an application for credit or any kind of stuff like that, you might want to skip whole sections depending on what data is entered in the form. So we're gonna say if family size is one, we're gonna skip right by a number of children and go right to CustomerSince using SetFocus.

Where do we do that? We put that in the AfterUpdate event. AfterUpdate fires when this value is changed. I've got a whole separate video on that; I'll put a link down below. We're gonna come in here, hit the builder button. That'll bring back our code builder. Where'd you go? There you are. All right, and here we're gonna say if family size equals one, then we're gonna skip the field. We're gonna say CustomerSince.SetFocus. I can't type today, folks. I apologize. Else NumChildren.SetFocus. You could just Exit Sub here or put that End If there because it's next in the tab order, but just in case the user later on moves fields around, you want to force where it's going after they finish entering in family size. Save it, come back out here, and now I'll put in a four and it goes to Number of Children. However, if I come up here and type in one, it skips it and goes to CustomerSince.

You can even do all kinds of things like disable the box, make it gray. There are lots of different options, but today we're focused on SetFocus. If you want to learn more about MessageBox, IfThen, IsNull, Tab Order, AfterUpdate, or any of the topics that I talked about in today's class, I've got more videos available. Look in the description down below the video, and you'll find links to all of those.

Now, there is another command called GoToControl that is very similar to SetFocus, but it has some unique properties of its own. We're gonna talk about that in tomorrow's class. But that is your TechHelp fast tip video for today. Hope you learned something. Live long and prosper, my friends. I'll see you tomorrow.

TOPICS:
SetFocus command in Access
Improving form navigation
Validating input with SetFocus
Design View for form editing
Button build event code
Checking for credit limits
Using IsNull function in validation
Exiting subroutine after validation
Using AfterUpdate event
Setting tab order for controls
Skipping fields with SetFocus
Handling form fields conditionally
Navigating forms with SetFocus

COMMERCIAL:
In today's video, we're learning how to use the SetFocus command to enhance form control navigation in Microsoft Access using VBA programming. Whether you're guiding users through fields based on existing data or improving input validation, SetFocus is your go-to tool. We'll demonstrate how to maneuver your form's cursor efficiently, improving user experience by navigating to specific fields based on conditions like credit limits or family sizes. Tune in to see how this functionality can streamline your database applications. 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 main focus of the video tutorial?
A. Learning how to create database tables in Access
B. Understanding and using the SetFocus command in VBA
C. Designing forms in Microsoft Access
D. Exploring different database relationships

Q2. What does the SetFocus command do in Microsoft Access?
A. It deletes the selected control
B. It changes the text color of a control
C. It moves the cursor focus to a specified control
D. It creates a new record in the database

Q3. Which programming language is used to demonstrate the SetFocus command in this video?
A. JavaScript
B. Python
C. SQL
D. VBA (Visual Basic for Applications)

Q4. Why might you want to use the SetFocus command to move the cursor to a specific field in a form?
A. To permanently lock the field so users cannot edit it
B. To enhance navigation and validate input on forms
C. To automatically generate a form report
D. To change the theme of the form

Q5. In the example given, why is there a check for a customer's credit limit before placing an order?
A. The default system message demands it
B. To ensure the customer has sufficient credit or to indicate that the customer may have bad credit
C. To always apply a discount based on credit limits
D. To verify the customer's age

Q6. What happens when the condition for the credit limit is not met in the example provided?
A. The form closes automatically
B. The order is placed without recording the credit limit
C. A message box appears and the cursor is moved to the credit limit text box
D. The system shuts down

Q7. What is the intended behavior for the SetFocus command when the family size is set to 1 in the tutorial?
A. Skip the number of children field and go directly to CustomerSince
B. Clear all fields in the form
C. Print a summary of the data entered
D. Lock all form fields

Q8. What method is used to determine when to execute the SetFocus command based on a change in form data?
A. OnLoad event
B. BeforeUpdate event
C. AfterUpdate event
D. OnClose event

Q9. Which alternative command to SetFocus was mentioned as a topic for the next class?
A. MoveToControl
B. ChangeFocus
C. GoToControl
D. SwitchFocus

Answers: 1-B; 2-C; 3-D; 4-B; 5-B; 6-C; 7-A; 8-C; 9-C

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 AccessLearningZone.com is here to guide you through using the SetFocus command to enhance your form control navigation within Microsoft Access. I am your instructor, Richard Rost, and we will be engaging with some developer-level content today, which means we will utilize some VBA programming. If you are new to VBA, I recommend you watch an introductory video that covers the basics in about 20 minutes.

The SetFocus command is essential for directing focus to a specific control on a form. For example, the cursor might be in the first name field, and with SetFocus, you can shift it to the last name field. This command is particularly useful for improving navigation and validating user input on forms.

Consider a scenario where an order cannot be placed unless a customer has a specified credit limit. If a customer either doesn't have a credit limit or it is negative, we want a message box to notify the user and move the cursor to the credit limit text box for correction. You begin by editing the code in the design view, adding validation to ensure that a credit limit exists and is non-negative. If these conditions aren't met, a message alerts the user, and SetFocus shifts the cursor to the credit limit field.

I've dealt with databases where certain placeholder values were used to indicate bad credit, even when the default value was zero. But to keep our example straightforward, once the SetFocus command is applied, the user is promptly notified and directed to enter the correct credit information.

SetFocus can also be utilized for easier navigation through form fields, avoiding unnecessary inputs. For instance, if there's an optional field like the number of children that's dependent on another field such as family size, SetFocus allows you to bypass it based on certain conditions. You can add this field to the customer form, ensuring it's properly listed in the tab order. When family size is updated, you can set conditions to skip unnecessary fields using SetFocus.

This may appear minor, but optimizing navigation can be a significant time-saver for users, especially in complex forms used frequently. It streamlines data entry, skipping fields when applicable data makes them redundant.

To implement these navigation improvements, you'll insert the relevant logic in the AfterUpdate event of the form, allowing changes to redirect focus automatically. Testing with values like family size will illustrate how fields are gracefully skipped or selected, enhancing the form's usability.

You can also explore other customization options like disabling fields or altering their appearance, but our focus here is on the SetFocus command. For more insight on other topics like MessageBox, IfThen, IsNull, Tab Order, or AfterUpdate events, additional videos with these themes are available.

We'll also discuss a similar command, GoToControl, in an upcoming lesson, as it has its own distinct features. With today's session, you've gained another tool to refine your Access forms. For a complete video tutorial with detailed instructions, visit my website using the link below. Live long and prosper, my friends.
Topic List SetFocus command in Access
Improving form navigation
Validating input with SetFocus
Design View for form editing
Button build event code
Checking for credit limits
Using IsNull function in validation
Exiting subroutine after validation
Using AfterUpdate event
Setting tab order for controls
Skipping fields with SetFocus
Handling form fields conditionally
Navigating forms with SetFocus
 
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 4/18/2026 6:45:52 PM. PLT: 1s
Keywords: TechHelp Access, SetFocus command, form control navigation, Microsoft Access VBA, focus management, tab order management, AfterUpdate event, customer form fields, cursor placement, GoToControl command comparison, NumChildren field adjustment, user input v  PermaLink  SetFocus in Microsoft Access