Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Home > TechHelp > Directory > Access > On Got Focus < Percent Bug | Requery in Place >
On Got Focus
By Richard Rost   Richard Rost on LinkedIn Email Richard Rost   3 years ago

Using the On Got Focus Event in Microsoft Access


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

In this Microsoft Access tutorial I'm going to teach you how to provide on-screen help users with the On Got Focus event in Microsoft Access. In my opinion it's a better solution than using Control Tip Text or Status Bar Text.

Members

Members will learn how to create a function so you don't need a separate event for each control. We also won't need an On Lost Focus event either.

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!

Pre-Requisites

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.

KeywordsOn Got Focus in Microsoft Access

access 2016, access 2019, access 2021, access 365, microsoft access, ms access, ms access tutorial, #msaccess, #microsoftaccess, #help, #howto, #tutorial, #learn, #lesson, #training, #database, on got focus, ongotfocus, on lost focus, onlostfocus, status bar text, control tip text, setfocus, set focus, move focus

 

 

 

Comments for On Got Focus
 
Age Subject From
3 yearsOn Got FocusJohn Davy

 

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 On Got Focus
Get notifications when this page is updated
 
Intro In this video, I will show you how to use the On Got Focus and On Lost Focus events in Microsoft Access to create dynamic on-screen help for your users. You will learn how to display helpful messages in a custom text box as users move between fields, set up basic VBA code to trigger these messages, and control the behavior so your help text appears and clears at the right times. I will also discuss the differences between using control tip text, status bar text, and this on-screen method, and walk through formatting options to make your help area stand out.
Transcript Welcome to another FastTips video brought to you by AccessLearningZone.com. I am your instructor, Richard Rost.

In today's video, I am going to show you how to use the On Got Focus event, and its cousin On Lost Focus, to provide on-screen help to your users, which I think looks better than control tip text or the status bar text. It involves a teeny tiny bit of programming. So I am going to slap the developer label on this one, but do not be scared. It is easy. I am going to show you exactly how to do it, and you are going to like it.

You are going to get this little help message right down here every time the user tabs from field to field or clicks somewhere, and you can specify exactly what it is.

Now, if you have never done any VBA programming in Access before, do not worry. It is easy. Do not be scared. Go watch my Intro to VBA. It is free. It is on my website and my YouTube channel. It is about 20 minutes long. It will teach you everything you need to know to get started with VBA. We literally need one line of code to do what I am going to do in today's class, so it is not hard - two, if you want to erase it.

Here I am in my TechHelp free template. This is a free database. You can grab a copy off my website if you want to. I have got my customer form.

If your users are not very savvy or if you have got some fields that just have weird information in them and you want to give some explanation as to what goes there, you could spell it out here in a big label. Or you could use something called a control tip text, which I have another video for. If you click on a field and go to Other over here in the properties, put a control tip text in, right? Put in here: This is the user's first name. Save that.

Now, whenever you go to this field, if you hover over it, you will see: This is the user's first name. I do not particularly care for that. I like this more for buttons, if you want to hover over a button and give someone more information. That is what I like control tip texts for. But for text fields, I do not really care for those. Again, I have got a whole separate video on control tip text, but I do not think it is suitable for this particular use.

The other option is to use status bar text. Instead of putting that there in the control tip text, there is a thing called status bar text, and that goes down on the bottom here in the status bar. So, save that, close it, open it back up again. You can see down here it says: This is the user's first name. But no one bothers looking down there. You can go through this and do stuff, and it says Form View most of the time, and you click there, but no one notices that.

If you have a situation where you really need to describe what is going on on the form to the user for one or more fields, and you want it to be more in their face, you do not want to pop up another form. I mean, that is always an option, but I like putting a box on the bottom of the form that describes what is going on. Yes, I am using this as the user's first name as a simple example, but I have had some databases that I built for customers that were like, "OK, this rate is the value from box four times the product of boxes three and six." That kind of stuff. Like tax forms, for example: "Add up lines four through eight and send us all your money." That kind of stuff.

So, let us give it a status bar text.

What I am going to use instead is an event called On Got Focus. It is right there. There is On Got Focus and On Lost Focus. Got Focus happens when this field gets the focus, when you either tab to it or you click on it, or if the form opens and it is the first field in the tab order, it will get focus automatically. Let us click on On Got Focus... Right, that opens up the VB code editor, which we saw in the Intro to VB class. Just for now, right in here, I am going to put: MsgBox "How you doing?" Save it. Close it. Close that. Close it. Open it. And we got our "How you doing?" Why? Because that is the first field in my tab order. So as soon as the form opens, we get that. I am going to click down here. Click there. I am going to click on that field: "How you doing?"

So that is On Got Focus.

Now, I obviously do not want it to say "How you doing?" every time you click on first name. I want a message down at the bottom. So let us make a spot to put that message.

First, let us get rid of "How you doing?" Let us go back in here. I have got a button up here that opens up my code editor. I have another video that covers how to do that. For now, just delete that. We do not need it right now. Goodbye.

Let us make a label down here on the bottom, as big as you think you need it to be. You could use a text box if you want to. If you have really long messages, you could have a scroll bar, but generally, I do not get that big. I am going to copy one of the existing labels. Copy, paste, Control-C, Control-V, and make this as big as you want it to be, like there.

Format it. Make it look pretty. I am going to go not red. Let us go blue. We will make it maybe 18 point. Whatever you feel is noticeable. You want a yellow background? Go ahead. Put a yellow background on it. I do not care.

Save that. Close it. Take a peek what we have got. All right. Static label. It says "Country." Okay, we are getting there. Back to design view.

Now double-click on this guy. Open up its properties. It is called Label30. I do not like that. Let us call this "myHelpLabel," just like that.

Next, I want to get rid of what is in there. So if I do not specify something, this thing shows up as blank. But be careful. Do not delete the label on the form, because if you do, it gets rid of the label. That is weird. It is just the way Access behaves. So undo. Go back there. What you want to do is get rid of the label caption in the properties, and that leaves a blank label behind. I know, it is weird. Access does some weird things. It is the same thing where if you had it in here and you resize the label, it gets all weird. See? Again, I clicked on it and it went away. So Control-Z to undo. You have got to be careful with it now.

Again, you could use a text box. I do not like text boxes because then sometimes people click on them and then they get focus - and then you can use an On Got Focus event to force the focus away. There are all kinds of tricks you can play. In fact, I am going to call an audible here. I like that. I did this originally with a label, but let us get rid of that. Let us do this with a text box. I was not thinking about that. That is another great example.

Copy and paste a text box. Delete the label that comes in with it. Make this guy again the same size, like this. I am going to format it. Let us make the format transparent background, and no border. There should never be a border on it. Let us see. If I do not like transparent, let us make this blue. Let us go with that later. Yes, that looks good. We will go 16 point. Looks good.

Now, let us give it a name. Labels do not have all the problems. With a label, you just modify the caption property, but I am thinking the text box might be cool too. Let us call it now. Let us call this our "helpText," since it is not a label anymore. All right, helpText.

Save it. Close it. Close it. Open it. It is still bound to country. Oh, watch this. Still got the country field value in it, so we have to get rid of the data in the box and leave it unbound.

Again, open up its properties. Go to Data. Get rid of the control source. Now we should get an unbound text box sitting there.

Now, the problem from before is the user can click on it and then see it. I do not like that. So this is a perfect example of how to use On Got Focus. We are going to say if this box gets the focus, push the user somewhere else, like first name.

Let us try that. Open up this guy's properties. Go to Events. Go to On Got Focus... and right here, all you have to say is: firstName.SetFocus. That means move the cursor, move the focus to that other field. There is also DoCmd.GoToControl, but I like SetFocus better.

Let us see how that works. Save it. Save it. Close it. Save it. Open it. Print it. Just do not print it.

So if I click down here now, you see it goes right back up there. Click - boom - goes right up there. See? Every time I click down here, nothing appears to happen, even though it is there. It is moving right up to the first name field.

You can also make this so it is not a tab stop. Open that up. Well, I am sorry, it is not in the properties, it is up top. No, I am sorry, it is in the properties, Other, Tab Stop. Set that to "No."

Now, let us get back to the original problem that we had: we need some help text to go in there. So, On Got Focus events for the fields that we want to put stuff in. We will start off with first name. Event -> On Got Focus... Now, what do we put in here? HelpText = "This is the customer's first name." That is it. Save it.

Let us do the last name -> On Got Focus... HelpText = "This is the customer's last name." And whatever other instructions you want to put in there. Save it. Close it. Close it. Close it. Open it. Look at that. "This is the customer's first name." If you click on last name: "This is the customer's last name." See, is not that cool?

That is a lot more noticeable than a little teeny tiny text down there, or better than a control tip text hover over it. If you want to, if something is really urgent and important, you can change the colors as well. Back to your code, you could say: HelpText.ForeColor = vbBlue. Maybe this one is urgent, so: HelpText.ForeColor = vbRed. Or, if you like to use the RGB function, you can go RGB(255,0,0). That is red, green, blue components. I have videos on that too. Go watch this one if you want to learn more about using colors in VB.

Now, save it. Close it. Close it. Come back in here. Look at that: now it is blue, and that one is red. If you want to control the color, you can control the background color with the BackColor property. You can put a border around it. You can change the font size. You can do whatever you want, moving from record to record.

Now, here is the problem. If you click on a field that does not have a Got Focus event, it does not change. It leaves it the way it was. So, for each one of these fields where you have a Got Focus event, you also want to have an On Lost Focus event. I will show you a way around this in the extended cut. There is going to be an extended cut for the members. For now, the simple way is to simply have an On Lost Focus event. Same as the On Got Focus event, but it happens when you leave the field. So, On Lost Focus, all we have to say is: HelpText = "". Reset the color if you want to, but you do not have to.

All right, and we will come down here to last name. If you click in last name got focus, drop this guy down, you can find Lost Focus right here without having to go back to the form. There it is, and it is down below, so I am going to slide this up so you can see it. HelpText = "" like that.

Now, back over here. Close it. Close it. Save it. Open it. First name, last name, nothing. Make the first name, go back over here, go back to last name. That allows you to show help where help is needed. You might not need something on every field.

I have got a couple more videos you might want to check out. This one is my Zoom dialog box one. I show you how you can, in the extended cut for the members, I show you how you can click on a field, and it will automatically pop open the zoom box so you can edit a large bit of text in a small field using an On Got Focus event.

In my Help System video, I show you how to build a much more context-sensitive help system, in depth, with rich text, the big help box that pops up. You could put colors and highlights in there. You can do an F1 key to give you context sensitive help. You can do a little question mark button next to a field. So this is for more in-depth help. You could put a little question mark button over here that says, "Click the question mark button for help" or "Press F1 for more help" and that thing will pop up.

Of course, if you like learning this stuff and you want a nice comprehensive course that goes from A to Z, you start here, you do this, you do this, you do this, instead of jumping around like I do with these FastTips videos, check out my developer lesson. Start with Developer 1, we go through all the basics and it gets more advanced as you go along.

I love doing these TechHelp videos, but they are not in any particular order. It is just whatever topic I get asked that day or questions I get. But this is my comprehensive course where I teach you everything A to Z.

There is going to be an extended cut, members. I do extended cuts for FastTips once in a while. Sometimes these videos start off as FastTips and I think they are going to take me five minutes, and by the time I lay everything out, I am like, you know what? I need more.

So members, we are going to make this a function so you do not have to put a separate On Got Focus event in every field on the form. We will make a function and we will do all of them at once to blank them, and then we will set whatever specific fields you want to have a message - they can have their own specific message. We will not need any On Lost Focus events either because our function will be able to see if the user specified an empty string.

Check it out - Silver members and up get access to all of my extended cut videos. There are hundreds of them now. Your membership is well worth the very tiny investment to keep my puppies fed and to keep these videos coming.

This has been your Fast Tip for today. I hope you learned something. Live long and prosper, my friends, and I will see you next time.
Quiz Q1. What is the main purpose of using the On Got Focus and On Lost Focus events in Microsoft Access forms as demonstrated in the video?
A. To provide real-time on-screen help messages for users as they interact with form fields
B. To automatically validate user inputs as they move between fields
C. To prevent users from entering data in read-only fields
D. To display pop-up dialog boxes for advanced data entry

Q2. Why does the instructor prefer on-screen help messages over control tip text or status bar text?
A. On-screen help messages are more noticeable to users
B. Control tip text can only be used with buttons
C. Status bar text cannot be changed at runtime
D. On-screen help messages cannot show long messages

Q3. How does the On Got Focus event work in Microsoft Access?
A. It triggers when a field is selected, either by tabbing into it or clicking on it
B. It triggers when the form is saved
C. It only runs when opening the form for the first time
D. It is used to handle form-level validation errors

Q4. What VBA code example is initially demonstrated for the On Got Focus event?
A. MsgBox "How you doing?"
B. HelpText = ""
C. DoCmd.Close
D. firstName.SetFocus

Q5. What is the recommended way to display the help message area on the form, according to the video?
A. Use an unbound text box formatted to fit the form design
B. Use a message box that pops up when fields are focused
C. Depend on the built-in status bar at the bottom of Access
D. Display the help message in the form title bar

Q6. What issue does the instructor mention when using a text box for help messages, and how is it handled?
A. Users can click on the text box and give it focus, so the code moves focus elsewhere
B. The text box is always visible, so it needs to be hidden with VBA code
C. The help text can only be a single line
D. The text box cannot display colored text

Q7. How can you prevent users from tabbing into the help message text box?
A. Set the Tab Stop property to No for the text box
B. Set the Enabled property to No
C. Use a hidden label instead
D. Lock the text box from the Format menu

Q8. When should you use the On Lost Focus event for fields with help messages?
A. To clear the help message when the user leaves the field
B. To validate the entered data
C. To permanently hide the help area
D. To lock the field from further edits

Q9. In the video, what method is used to change the color of help messages dynamically?
A. Setting the ForeColor property of the help text control in VBA
B. Changing the default form color in properties
C. Creating a new label for each message with a specific color
D. Using conditional formatting in Access

Q10. What advantage is mentioned in the extended cut version for handling help messages more efficiently?
A. Creating a function to handle help messages for all fields, reducing redundant code
B. Using macros instead of VBA for help messages
C. Restricting help messages to only one field per form
D. Automatically displaying help on all fields regardless of user actions

Q11. Why might you want to use a more advanced context-sensitive help system in Access, as referenced in the video?
A. For forms with complex or detailed fields where simple messages are not enough
B. To avoid any programming in VBA
C. So users can skip entering required data
D. To discourage users from reading help

Q12. If a field does not have an On Got Focus event, what happens to the help message area when it is selected?
A. The help message area remains unchanged from the previous message
B. An error is displayed to the user
C. The help area automatically clears itself
D. The form closes automatically

Answers: 1-A; 2-A; 3-A; 4-A; 5-A; 6-A; 7-A; 8-A; 9-A; 10-A; 11-A; 12-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 improving your Microsoft Access forms by using the On Got Focus and On Lost Focus events to display helpful messages to your users. This approach offers a more prominent and effective way to provide guidance than using control tip text or status bar messages.

Often, when building Access forms, you want to make sure users understand what information should go in each field, especially if some fields require complex or non-obvious data. While you can provide instructions in a large label on the form or use the control tip text property to display a tooltip when someone hovers over a field, these methods have limitations. Control tip text works well for buttons, but for text fields, it can be easy to overlook. Status bar text displays messages at the bottom of the Access window, but many users do not notice it because their attention is on the form itself rather than the status bar.

Instead, I recommend creating a dedicated help area directly in your form, such as a box at the bottom, that updates dynamically as users move from field to field. This ensures your instructions are clear and obvious right when the user needs them.

Setting this up requires just a little bit of VBA, but if you have never done any VBA programming in Access, do not worry. My introductory VBA lesson, available for free on my website and YouTube channel, covers everything you need to get started. For the solution in this tutorial, we only need a single line of code per event, so it is very manageable even for beginners.

To start, I opened my TechHelp free template database, which you can download from my website. Suppose your form includes fields where users may need additional explanation. You could use control tip text, by entering a brief description in the property sheet under 'Other,' but, as mentioned, I find this more helpful for buttons and less so for text fields.

Similarly, status bar text shows a description in the status bar at the bottom of the screen when you select a field. However, users rarely read information in the status bar, so important instructions can be missed.

To provide more prominent guidance, I suggest adding a box at the bottom of your form to display instructions. You can use either a label or a text box for this. While a label is easy for displaying static messages, using a text box gives you more control. For example, you can easily change the formatting, such as font size, color, or background, and if your help messages are lengthy, you can even provide a scrollbar.

If you use a text box, be aware that users can accidentally click into it, which gives it focus. You can take advantage of the On Got Focus event to move the focus back to the first actual data field, preventing users from getting stuck in the help text box. Also, set the tab stop property for the help text box to 'No' so that pressing Tab never brings focus to it.

Now, for the main functionality: whenever a user clicks on or tabs to a particular field, you want the help text box to display relevant instructions. Do this by using the On Got Focus event for each field. In the event's VBA code, simply set the value of your help text box to the message you want. You can further enhance this by changing the font color or other formatting properties so certain instructions stand out more.

For example, when a user navigates to the 'First Name' field, the help text could display a message like 'This is the customer's first name.' When they move to 'Last Name,' the message updates accordingly. This approach provides much clearer guidance than the older methods.

One issue to be aware of: if a field does not have an On Got Focus event, the help message does not update and will continue showing the message from the previous field. To resolve this, use the On Lost Focus event for each field where you display help text. In its VBA code, clear the help text box by setting its value to an empty string. This way, the help message appears only when it is needed and disappears when you move away from the field.

If you want to streamline the process, in today's Extended Cut for members, I demonstrate how to create a function that handles all these updates automatically. By centralizing the logic, you will not have to write separate On Got Focus and On Lost Focus events for each field. The function can set the help message for the relevant fields and clear it for others as needed. This saves time and keeps your forms cleaner and easier to maintain.

If you are interested in more advanced help systems or additional techniques, I encourage you to check out my other videos. For example, I offer one that shows how to use On Got Focus events to display a zoom dialog box for editing large amounts of text, and another on building a full-featured context-sensitive help system that opens a rich text help window, supports F1 key help, and more.

For those wanting to learn Access development from the ground up, my comprehensive Developer series provides a step-by-step curriculum that covers everything in logical order. While my TechHelp videos answer specific questions as they arise, the Developer courses are structured to take you from beginner to advanced user.

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 Using the On Got Focus event in Access forms
Using the On Lost Focus event in Access forms
Creating an on-screen help message area
Adding and formatting a label for help text
Switching to using an unbound text box for help
Naming and setting up the unbound help text box
Ensuring the help text box cannot receive focus
Setting the text box Tab Stop property to No
Writing VBA to display help text on field focus
Writing VBA to clear help text on field lost focus
Changing help text color with VBA
Changing help text background and font size
Preventing users from editing the help text box
Using SetFocus to control field navigation
 
 
 

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: 1/15/2026 10:00:52 AM. PLT: 2s
Keywords: FastTips Access Fast Tips on got focus, ongotfocus, on lost focus, onlostfocus, status bar text, control tip text, setfocus, set focus, move focus  PermaLink  On Got Focus in Microsoft Access