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 > On Activate < Force New Page | Activate v Got Focus >
On Activate
By Richard Rost   Richard Rost on LinkedIn Email Richard Rost   3 years ago

On Activate Event to Highlight Active Form in 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 use the On Activate event to highlight the active form and turn it yellow when you click on it, to make it more easily visible to the user.

Harper from Seattle, Washington (a Platinum Member) asks: Is there any way to highlight the current form that has focus? Our database uses a bunch of different forms, and sometimes it's hard to keep track of which one you're on. I know how to use conditional formatting to highlight the field you're on, but it would be nice if the whole form turned yellow too. I tried using the On Got Focus event for the form, but that doesn't seem to do anything.

Update

  • Thanks to Thomas Gonder for posting that the Activate and Deactivate events don't fire if you use acDialog when opening your form, or if the form's Popup property is set to Yes. For me, personally, this is never a problem because I absolutely hate the PopUp property and never use it. If you open a form using acDialog, that essentially sets the Modal and PopUp properties to true.

Members

There is no Extended Cut, but here's the database for the Gold members.

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

Usage

  • Form Level Variable: Dim StartColor As Long
  • On Load Event: StartColor = Me.Detail.BackColor
  • On Activate Event: Me.Detail.BackColor = vbYellow
  • On Deactivate Event: Me.Detail.BackColor = StartColor

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 Activate Event 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 Activate Event, Form Highlighting, Form Focus, Active Form, User Experience, Form Navigation, Form Activation

 

 

Comments for On Activate
 
Age Subject From
3 yearsDoesn't Always WorkThomas Gonder
3 yearsOn ActivateJohn 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 Activate
Get notifications when this page is updated
 
Intro In this video, I will show you how to use the On Activate event to highlight the active form in your Microsoft Access database. We will talk about storing and restoring the form's background color using a form-level VBA variable, and cover how to change the form's color when it gains or loses focus using the Activate and Deactivate events. This is a developer-level tutorial that provides a step-by-step solution for making it easy to see which form currently has the focus in your Access application.
Transcript Today, we are going to see how to use the On Activate event to highlight the active form in your Microsoft Access database.

Today's question comes from Harper in Seattle, Washington, one of my Platinum members. Harper says: Is there any way to highlight the current form that has focus? Our database uses a bunch of different forms and sometimes it is hard to keep track of which one you are on. I know how to use conditional formatting to highlight the field you are on, but it would be nice if the whole form turned yellow too. I tried using the On Got Focus event for the form, but that does not seem to do anything.

Yes, you are right, Harper. The On Got Focus event for the form does not work most of the time. I actually have a separate video on this coming up soon where I will explain why it does not work, how you can get it to work, and what it is for.

Today, let me show you how to do what you want using the On Activate event.

Now, this will of course be a developer-level video, which means you are going to need to know some VBA. It is not hard though. We literally can do this with four lines of code. I tried it earlier and, yes, four lines and you are done. Well, four lines in each form because you have to do this for each form you want to have highlighted.

If you have never done any VBA programming before, go watch this video. It is about 20 minutes long. It will teach you everything you need to know to get started. Go watch this first. Then, go watch this video on variables. We have to store the form's opening color in a variable. Otherwise, we will lose it. We have to store that in a variable. Go watch this first.

We are going to use a form-level variable. That is a variable that has scope on the form that it is on. Other forms cannot see it or use it. It is unique to that form. Go watch this one. Those are all free videos. They are on my YouTube channel and my website. You will find links to them down below in the description under the video. Click on them, watch them, and come on back and I will show you how to do this.

Here I am in my TechHelp free template. This is a free database. You can download a copy on my website if you want to, but any database will work.

Every form that you open has a detail section and, in that detail section, it has a color property under Format. There is Background Color. Where are you? Back Color, right there.

If it has a theme-level color like this one here, I do not like theme colors. I usually pick one of these standard colors down here. That standard color is basically stored internally as a number. We are going to grab that number and store it in a variable as soon as the form opens so we do not lose it because we have to be able to switch back to it.

For the form, click on the form's properties. Go to Events and use the On Load event or On Open. Either one works for this. That will open up your VBA editor.

Before we can set that, we are going to come up here up top and make a form-level variable. Say Dim StartColor As Long. It is going to hold the color. We are going to call it StartColor.

When the form loads up, we have to set that value. So, StartColor equals - how do I get the color of the form? Well, it is technically the detail section of the form. So it is Me.Detail.BackColor. That is what we want.

If you also want to do sections like the header, the form header, the form footer - those are different. You can do Me.Section(acHeader).BackColor like that. There is also acFooter, that is for the form header and footer. There are lots of different things you can refer to, but for this video, we are just going to stick with the detail section.

So, what have we done so far? We dimmed a variable called StartColor. When the form opened up, we set that value equal to whatever the current background color of the form is.

Now, when this form gets activated using the On Activate event - again, click in the form properties, go to Events, find On Activate. Scroll down. Right there: Activate and On Deactivate. This happens when you go to a form and when you leave a form, you get Deactivate.

This will happen either when the form is opened or if you click on the form. For example, right now, the main menu is not activated; if I click on it, it just got activated. Now, if I come back over here, this one gets activated. Not when it is in design view, but in form view it does.

Go into the On Activate event, and here we are going to say Me.Detail.BackColor equals whatever color you want. You can use one of the constants, like vbRed or I like vbYellow. Or you can use the RGB function if you want to. I have a whole separate video on that. I will put a link to it down below if you want to specify the exact color.

This video teaches you all about the RGB function and you also learn about the hex colors, like the things you see on the web - these guys. But for now, I am just going to turn it yellow. Let us stick with the default yellow.

We also need the Deactivate event for when we leave this form. Drop this box down, find Deactivate. There.

Here we are going to go and say Me.Detail.BackColor equals - what did we start with? That is StartColor.

Save it. Close it. Let us close you down and open it back up again. Look, it went to yellow. See that? Because the form got activated when you opened it. If I click on the one behind it, look at that. It just got deactivated, and it went back to its original starting color. See?

Let us do that to the main menu too. Right-click, Design View, and just repeat all those steps I just gave you.

On Load event or the On Open event? First, let us come up top and declare our variable. Dim StartColor As Long.

The Unload event, do not worry about the DoStartUp. That is for me.

StartColor = Me.Detail.BackColor.

Then, in the form Activate event - where are you? Activate. Once you learn these, it is easier to find stuff over here.

Me.Detail.BackColor = vbYellow.

Then, in the form Deactivate event:

Me.Detail.BackColor = StartColor.

Save it. Give it a quick Debug – Compile. Close it. See how that got activated again? Close it. And one more time, open it up. I have code that moves my form over. We are open up. We are going to go over the customer form. Notice how it got the focus like that, and now it is yellow. Do that, and if I come back over here, see? Is not that neat? Now you have no way to miss which form currently has the focus.

You just have to do this in every form that you want to light up. Could you do a global function? Yes, but you are still going to have to put that code in each form. You are going to have to put an Activate, a Load, and a Deactivate event. I just put the four lines of code in each form that you want. If you put them in, like I have these from my template, Continuous and Single, put those in your form templates so when you create a new blank form based on copying one of these, it will copy over all that code. That is another reason why I have these. It has all my settings and stuff that I like from my Single forms and my Continuous forms, and then I just base new forms off of these. Put that code in there and you will not have a problem. Otherwise, take a Sunday, go through all your forms, put all that stuff in there. There you go.

If you want to learn more about this kind of stuff, if you enjoy it, I cover the On Activate, Form Open events, all kinds of different events and event timing, especially in my Access Advanced Level 1 class. Yes, it is based on macros, but there is lots of good stuff in here that I cover before VBA that will teach you all kinds of things like how the events fire, what order they go in, that kind of stuff.

In my Access Developer Level 41 class, I cover a lot more cool stuff with these types of events, including a form zoom. You can take a form like this and zoom in and out. So, if you make this form bigger, if you click and drag it, it will actually make all the controls on this form larger. You have a tiny one to fit your phone, and you can click and drag it on your giant monitor, and if you are like me and have really bad vision, it is easier to see. It will make the font size larger and stuff, too. That is covered in Developer 41. I mention this class because I do cover a lot of stuff with the On Activate event as well.

So Harper, there you go. I hope that answers your question. That is your TechHelp video for today. I hope you learned something. Live long and prosper, my friends. I will see you next time.
Quiz Q1. What is the main goal of using the On Activate event in a Microsoft Access form as described in the video?
A. To highlight the currently active form so it is visually obvious which form has focus
B. To automatically save the data in the form when it becomes active
C. To close all other forms except the one being activated
D. To validate data on the form before it is used

Q2. Why does the On Got Focus event NOT work reliably for highlighting the entire form?
A. Because it only triggers for controls, not for forms themselves
B. Because it runs before the form is visible
C. Because it only works in datasheet view
D. Because it requires conditional formatting to function

Q3. Where is the Back Color property located for a form that you want to highlight?
A. In the detail section under Format properties
B. In the data source of the form
C. In the database options menu
D. In the VBA references window

Q4. Why is it important to store the starting color of the form in a variable when using this technique?
A. So you can restore the original color when the form is deactivated
B. So the color is saved to the database for future use
C. So you can apply the same color to all forms automatically
D. So you can print the color value in a report

Q5. What type of variable should be used to store the starting color of each form?
A. A form-level variable
B. A global module-level variable
C. A local variable inside each event procedure
D. A property of the Application object

Q6. What VBA code would you use to capture the original background color when the form loads?
A. StartColor = Me.Detail.BackColor
B. StartColor = GetFormColor()
C. StartColor = Me.BackColor
D. StartColor = Application.FormColor

Q7. When should you apply the highlighting color (such as yellow) using VBA in this setup?
A. In the On Activate event of the form
B. In the On Load event only
C. In the On Got Focus event
D. In the On Error event

Q8. How do you revert the form's background color to its original state when it loses focus?
A. In the On Deactivate event, set Me.Detail.BackColor to StartColor
B. In the On Open event, set Me.Detail.BackColor to vbWhite
C. In the On Got Focus event, use conditional formatting
D. In the On Deactivate event, close the form

Q9. What must you do if you want multiple forms to have this highlighting behavior?
A. Add the VBA code to each individual form you want highlighted
B. Set a database-wide option for activated form color
C. Only write the code once in a module and all forms inherit it
D. Only use conditional formatting rules in each form

Q10. Why is it helpful to use form templates for this technique?
A. So the necessary code and settings are copied automatically to new forms
B. So Access automatically installs the VBA editor for you
C. So all forms print in the same color
D. So the Ribbon interface is deactivated

Q11. What happens if you only use the On Activate event to set the highlight color, but do NOT set the original color in the On Load event?
A. The form cannot revert to its original color after losing focus
B. The code will not compile in Access
C. The form will automatically use the default system color
D. The form will stay highlighted even when already active

Q12. Which of the following VBA color values is suggested in the video for highlighting the active form?
A. vbYellow
B. vbGreen
C. vbRed
D. vbBlue

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 is all about using the On Activate event to highlight the active form in your Microsoft Access database.

The question today is how to make it easy to see which form currently has focus. With multiple forms open in an Access database, it can sometimes be challenging to figure out which one you're working on at the moment. While conditional formatting can be used to highlight the specific field that is active, it would be nice to have the whole form visually stand out by changing its background color whenever it is active.

First off, the On Got Focus event for forms is not usable for this purpose. It simply does not work the way most people would expect, and I have a separate video planned where I discuss why that is and how you can use it properly in other scenarios. For highlighting the active form, what you really want is the On Activate event.

Now, be aware that today's lesson does require a little familiarity with VBA. You do not need to be a programming expert, though, because this effect can be achieved with just a few simple lines of VBA code for each form you want to highlight. If you are new to VBA, I recommend watching my introductory VBA tutorial first. After that, check out my lesson on variables, since you need to store the form's original background color in a variable. This step is important because you'll need to put the old color back when the form loses focus. These videos are all available for free on my website and YouTube channel.

The approach we are going to use involves a form-level variable. This variable is local to each form, so it will not interfere with other forms' values or settings. When you open a form in Access, each one has a detail section, and that section's background color can be set in the Format properties. By default, the background color might use a theme color, but for this trick, I recommend setting a standard color, which Access tracks internally as a number. The key here is to retrieve that background color as soon as the form loads and save it in your variable.

To set this up, go to the form's properties and select either the On Load or On Open event to run your initialization code. At the top of your form's module, declare a variable (for example, StartColor) to hold the starting color. Set this variable to the current background color of the form's detail section when the form opens.

If you're interested in working with the header or footer sections as well, you can use their corresponding sections in your code, but in this lesson, we'll keep it simple and just target the detail section.

With the original form color saved, you'll next set up an On Activate event. This will fire whenever the form gains focus, whether when it is first opened or when you switch back to it from another form. In this event, change the background color to something bright and obvious, like yellow. You can use VB color constants, such as vbYellow, or create a custom color using the RGB function. For more information on using specific color codes, check my separate video on the RGB function.

You'll also want to handle the On Deactivate event for the form. This one triggers when you leave the form, either by switching to another form or closing it. Here, just reset the background color to the original value you stored earlier.

Once everything is set up, you can see the effect in practice. When you open the form, it will flash yellow to indicate it's active. If another form takes the focus, the first form reverts to its original color, and the newly active form turns yellow instead. This provides an unmistakable visual cue about which form currently has the focus in your database application.

You will need to repeat this setup for each form where you want this effect. There is no practical way to create a global function to manage all form colors without still having to assign the necessary events on each form, so it is easiest to just put those four lines of code for Load, Activate, and Deactivate into every relevant form. If you use form templates for single forms or continuous forms, it's even easier. Just add the code to your template forms so any new forms you create will inherit the highlight behavior automatically. If not, set aside some time to retrofit your existing forms.

If today's topic interests you and you want to learn more about form events, I go into much greater depth on the timing and order of events, along with plenty of event-driven programming tips, in my Access Advanced Level 1 class. For even more advanced event handling, like dynamically zooming forms and resizing controls for accessibility, check out my Access Developer Level 41 class, where the On Activate event also plays a big role.

And there you have it. With these steps, you can make it obvious which form is currently active in your Access application. For a step-by-step video demonstration of everything in this article, visit my website at the link below.

Live long and prosper, my friends.
Topic List Using the On Activate event to highlight the active form

Storing the form's original BackColor in a variable

Declaring a form-level variable for color storage

Setting the form-level variable using the On Load or On Open event

Identifying and using the detail section's BackColor property

Changing the form's BackColor in the On Activate event

Restoring the original BackColor in the On Deactivate event

Applying the same code to multiple forms

Differences between detail, header, and footer section BackColor

Adding event code to form templates for reuse

Using standard color constants and the RGB function for color selection
 
 
 

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/29/2026 11:54:07 PM. PLT: 1s
Keywords: TechHelp Access On Activate Event, Form Highlighting, Form Focus, Active Form, User Experience, Form Navigation, Form Activation  PermaLink  On Activate Event in Microsoft Access