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 > Tag Property < Field Value Substitutions 3 | Edit Mode 2 >
Back to Tag Property    Comments List
Pinned    Upload Images   @Reply   Bookmark    Link   Email  
Transcript
Richard Rost 
          
2 months ago
Today we are going to talk about a seldom-used and seldom-known property called the tag property. We are going to see one way you can use it in your Microsoft Access database.

One little property that most people do not know about is this thing called the tag property. It is on the "Other" tab, and it is down here called "Tag." It just says "Extra data to be stored with the object." They do not really tell you much about what it is used for, but you can do some pretty cool stuff with this little guy.

Lots of things have a tag property - text boxes, check boxes, forms themselves have a tag property. It is just a place where you can store little extra bits of information, basically for yourself to do something with.

Let me give you one simple example, and then tomorrow we are going to go over a more detailed example. Let us say you want to give the user some instructions when they go from field to field. There are a couple of ways you can already do this.

You could use the control tip text, which is little text that pops up when they hover over a field. That is kind of boring. You can use status bar text, which is the little text that appears down here. I have got videos that cover both of these, but these are kind of boring too.

Let us say you want to make yourself a nice big instructions label over here. As the user moves from field to field, you want to display big instruction information in there for them, like I did right here. When they click on "Is Active" or tab to it, it says, "Is this customer active on our mailing list?" It explains what that field is all about. This is nice and big, and as you move from field to field, this can change.

We can store that text in the tag property of each of those controls. Then, as we change focus using our got focus and lost focus events, we can update this text.

Now, you are probably saying, Rick, why do not I just put that in the on got focus event itself, put the extra text in there? Well, this is just a better way to do it. It is easier. You do not have to have a separate event for each one of these controls. I am going to show you a nice, cool, easy way to do it.

First, we have some prerequisites. I was not just going to let you off easy. I am going to show you some neat new stuff.

First, start off with Intro to VBA. If you have never done any VBA programming before, go watch this course. It will teach you everything you need to know in about 20 minutes.

We are going to use the Screen.ActiveControl so we know what control we are sitting on and we can grab its tag property. We are going to use the On Got Focus event. In this On Got Focus event video, it is a fast tip, so it is short. I did do something very similar, but I did not use the tag property. So we literally hard-coded it into each field's events, which we are going to avoid doing in this video. But go watch this one - it is a good background.

Today, we are going to do something much cooler. We are going to use an event handler function so we can just put this in the event. We can just make a little function. We do not have to send it any information because the data will be stored in the tag property.

So today, think of today like the On Got Focus fast tip on steroids.

This is my TechHelp free template. You can grab a copy of this database if you want to from my website.

Now for the purposes of class, we are just going to delete all of this stuff over here. We do not need it. I am going to copy one of these labels, Control+C, and then Control+V, and then we are going to bring that guy over here. This will be our instructions label. This is where the instructions will show up, right there. We will format it, make the text bigger, maybe 18 point, make it blue, and bold it. The user cannot miss it.

Now you are going to go to each property where you want to have instructions in it, like the customer ID here, and go to the tag property. It is on the Other tab. This is the customer ID. You cannot change it. Then we will go to the Is Active text box. Is the customer on our mailing list or not? Stuff like that.

First name. The. Last name. We will put in here just "Last". Some of these are self-explanatory. Last name. Primary email address. Phone number. I am just putting this up in here now so it shows up. Address you might want to have "Street address only," that kind of stuff.

Country, that kind of stuff. So you put all your tags in here. Save it. All that data is stored in form design. You do not have to go into your VBA if you want to change it. It is much, much easier for you as a developer, too.

Now we are going to use a little function that is going to say, "Hey, what field is the user on? Which field has focus?" We are going to get that tag and put the tag in the instruction label.

We have to name this guy. I forgot to name it. Let us call this "Instructions." Let us call it "InstructionLabel." The initial caption can be blank. You can make it blank over here, though. Do not blank it in here because it will resize and get all messed up. Always change the caption property over here.

InstructionLabel. We are going to put the tag from here in the InstructionLabel caption.

Let us go to our VBA editor. I put a little button up here on my control tip so I can hit View Code. It brings me right into the VBA editor. If you do not have that, then you can just go to any one of these controls here. Just go to events, pick any event, and it will drop you in here. Then I am just going to delete that event.

Let us go up top. We are going to make two little functions. They have to be functions for event handlers.

Private Function ShowTip like that.

InstructionLabel.Caption = Screen.ActiveControl.Tag

So give me the tag property of the active control and put that in the instruction label's caption. If I move off of that, everything should camel case. We are good. That is it. One line of code.

Then we are going to make a HideTip function.

Private Function HideTip. And this literally is just empty string.

Debug Compile. Save it. Close it. Close it. Close it. Open it.

Now, it is not working yet. Why? We have to specify those functions in the On Got Focus and On Lost Focus events for these different text boxes.

This is where it comes in handy. Open up the properties. Now just pick all of the fields individually. Click on one, hold down the shift key, click on the other ones, or you can draw a box that touches them. Make sure you get just the text boxes, not the labels at all.

I have all of the text boxes selected. Now go to On Got Focus and set it to =ShowTip, like that. That sets that for all of those controls.

For Lost Focus, =HideTip.

If you do not have any controls on here that do not have tips in them, you do not even need the HideTip because if you tab from one field to the other, if they all have tips in them, then ShowTip will just show the next tip. But I have got a couple down here that do not have tips. You probably do not need tips in first name, last name, and so on like that. Those are pretty self-explanatory.

Save it. Close it. Open it. See? And that is nice.

Now you probably noticed when the form opened, it did not run. We also have to fire that event when the form opens. But here is the problem. When the form opens, Screen.ActiveControl does not have a value yet.

Watch this here. Design view. Let's go into either On Load or On Open, or I know some of you were thinking On Current, right? All three of those run when the form first opens. But at that point, Screen.ActiveControl does not have a value.

So what do you think? How would you solve this problem? How would you get this to run the first time without having to hard-code the text? How would you get it to get that tag property when the form opens? Pause the video and see if you can figure it out and put your comments down below if you think you have got it solved. Watch the rest of the video. I will give you the solution in just a second.

The key is to use a timer event with a very, very short pause. I have covered this in a couple of videos. What we are going to do is in the form's properties - let me get rid of this On Load that I put in here. Hold on. Get rid of you. Goodbye.

In the form's properties, we are going to find the timer interval and set that to something really short, like 500. That is half a second. These are milliseconds. And for the On Timer event, we are going to come in here and say ShowTip and then Me.TimerInterval = 0. That effectively turns the timer off.

So the form will open, Screen.ActiveControl will get its value because you will have focus on a field now, ShowTip will run, and then the timer gets turned off.

We are going to debug compile once in a while. Close it, close it, open it, and there it is. See, it takes a second, but it shows up. You can make that timer interval really short. Half a second might even be too long. Let us try 200 in here. Do not go too short, though. Oh, yeah, there it is. Now it just runs.

I covered that timer interval trick in this Load Faster video. This is a great and awesome trick to do if you have got stuff that calculates, like you have got a form that opens like a dashboard form and it has got sales it has to calculate. What you do is you load the form first so all the fields and everything displays, and then you have that timer event kick off the calculations. So the form displays, the user sees something, and then you can have this show up while it is actually calculating.

Otherwise, if you have got those all in functions bound in your text boxes like that, the user sees nothing while the calculations are going on in the background.

Coming up tomorrow, we are going to do something else with the tag property. We are going to loop through all of the fields on a form. What we are going to do is, in this Edit Mode video (go watch this before tomorrow), basically, when we open up a form, it is locked. Every field in here is locked so people do not accidentally make changes. If you want to edit the data, you click Edit Mode and then it flips over to where you can edit it. In this video, we are using the Allow Edits property, which affects every field on the form.

So, using the tag property, what we can do is lock whichever fields we want to be locked but leave some of them open, like maybe you want to leave notes open or something like that. With the tag property, just mark the fields you want locked. Then when they go into Edit Mode, we can loop through all of the controls on the form and only lock the ones that are supposed to be locked.

We will do that tomorrow in our TechHelp video.

Of course, if you like this stuff, if you like learning with me, if you enjoy my programming lessons, go check out my developer lessons on my website. I have lots of them. I am up to like 50 now. So if you want to learn VBA programming and Access, this is the place to do it.

That is going to do it for today. Folks, that is your TechHelp video. I hope you learned something. Live long and prosper, my friends. I will see you tomorrow.

TOPICS:
Introduction to the Tag property in Access controls  
Using the Tag property to store field instructions  
Setting up an instructions label on a form  
Formatting a label for user instructions  
Populating the Tag property for different controls  
Using the On Got Focus and On Lost Focus events  
Writing a ShowTip function to update the label  
Writing a HideTip function to clear the label  
Assigning event handler functions using properties  
Selecting multiple controls to assign events  
Updating instructions label dynamically on focus change  
Handling form open when Screen.ActiveControl is not set  
Using the Timer Interval and On Timer event  
Triggering ShowTip on form open with a timer  
Disabling the timer after the ShowTip runs  
Adjusting Timer Interval for optimal delay

COMMERCIAL:
In today's video, we are learning about the seldom-used tag property in Microsoft Access and how you can use it to store custom instruction text for each field on your forms. I will show you step-by-step how to set up an instructions label that automatically updates as users move from one field to another using the tag property and simple VBA functions, all without the need for separate events for every control. You will also see a cool trick using the form's timer event to display your instructions right when the form loads. Tomorrow, we will continue working with the tag property, so be sure to check back for that. You will find the complete video on my YouTube channel and on my website at the link shown. Live long and prosper my friends.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Tag Property.
 

 
 
 

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 2025 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 6/17/2025 11:07:31 AM. PLT: 1s