Caption
By Richard Rost
3 years ago
How to Use the Caption Property in Access
In this Microsoft Access tutorial, I will show you how to use the caption property. We will set the field caption property in a table and see how it affects queries and forms. We'll change the label and button caption properties to make a quick hotkey. Then I'll show you a little trick with Access VBA to set the form caption property based on the first name and last name of the displayed customer.
Links
Courses
Keywords
access 2016, access 2019, access 2021, access 365, microsoft access, ms access, ms access tutorial, #msaccess, #microsoftaccess, #help, #howto, #tutorial, #learn, #lesson, #training, #database, ms access caption property, Label.Caption, How to Specify a Caption, Changing the Caption Property, description property, query column header, form label hotkey, button hotkey, button alt key press
Subscribe to Caption
Get notifications when this page is updated
Intro
In this video, we will talk about the caption property in Microsoft Access and explore some useful tricks you might not know. You will learn how the caption property affects field labels in tables, forms, and queries, how it interacts with the description property to provide form status bar instructions, and how to create keyboard shortcuts using captions. We will also look at how to change caption properties dynamically with VBA, including updating form and control captions based on current data. This video is packed with practical tips to make your Access databases more user-friendly.
Transcript
Welcome to another Fast Tips video brought to you by AccessLearningZone.com.
In today's video, we're going to talk about the caption property. Even if you know what the caption property is, you might not know these tricks I'm going to show you. I have a couple of tricks up my sleeve.
Let's talk about the friendly neighborhood caption property.
Many things in Access have a caption property, and sometimes they behave differently than in other places. For example, if you look in a table, let's go to the customer table here. You'll see that fields like first name, last name, whatever, have a caption property down here.
I don't often use this caption property, but if you do put something in there, this caption will become the label that's associated with it when you bring this field into a form. It will also be the column header in a query. For example, if you don't want it to say first name without a space in the middle, you can come down here and put first name as the caption. When you bring this into a form or a query, it will look like that. It's just a little time-saver. Let me show you.
Let's go to the single form here, Design View. I'll change this form so it gets its data from the customer table. Now, when I go to Add Existing Fields, if I bring in first name and last name, click and drag, drop it over here, you can see last name doesn't have that space. Let me make these black so you can see them better.
Last name does not have that space because it just makes the label exactly what the field name is, but this guy's got a space in there. So it's a bit of a time-saver. That also happens when you make a query. Create Query Design based on the customer table. If I bring in first name and last name, and then run this, you'll see the column headers accordingly.
Now, I personally don't like that for the column headers because, for me, my end user should never be using queries directly. They should be interfacing with forms and reports only. Queries are for me if I want to run a query and see what the actual field name is instead of some other substitute for it. So I don't like that myself for queries. That's one reason why I generally don't use the caption property in the table.
A similar thing that a lot of people don't know - and I cover this in my Access Beginner courses - in addition to the caption, there's also this description over here, which is optional. Usually, I say that's for you, but keep in mind, if you put something in there, it's going to show up in the status bar on the bottom of a form whenever the user tabs to that field. For example, "This is the customer's first name." If I put that in there and save it, now, again, if I build a form - I should have saved this change before, sorry - let's make this bound to the customer table again.
If I add a field, let's add first name and last name again. Save it. I'm going to close it and reopen it. Notice down here it says "Form View." When I tab, look at that - I just tabbed to the first name field. Here's the caption, and there's the description; it pops up down there. You can use that for notes for yourself, or if you want to give instructions for the user of the database, you can put it in that description field.
Now, as far as the actual caption goes in forms, let's go to the customer form here. You'll see captions in a lot of different controls. Labels have a caption property, obviously, buttons have a caption property, and the form itself has a caption property. If I go to Design View, open up one of these controls, properties, and go to the All tab, you'll see there's "Caption" right there. You can put whatever you want inside there; we know that one already. See, first name, there's the new caption.
There are some tricks you can do. When it comes to text boxes, this label is attached to this text box. See how they're attached? As long as it's attached, you can come over here with the caption and you can put an ampersand in front of any of these characters, and that becomes like a hot link. If I put ampersand name like that, first name, hit tab, notice you get the little underscore there underneath "first name." What does that mean?
Let me save this and show you. If you have a field that you like to jump to a lot, let's say I tab down here, and I want to jump back up to first name, Alt+N, and there you go, it will jump you right back to that field. So if you have a couple of different fields where you jump around different spots in your forms, you can assign little caption hot keys to them like that, with a little ampersand sign.
The same thing goes for buttons. If you put an ampersand in front of the caption of that button, that means Alt+C will now jump you to that button. If I open this up and press Alt+C, I just pushed that button. That's cool.
Another trick I teach in my classes when it comes to captions is, I've got this label caption right here, all nice and set. I've got the dimensions set, the color, all that. If I want to change this, put an exclamation point after it, and look at that. I pressed enter and it changed the size of the caption, trying to auto fit it. Let me undo that.
If you want to make a change to this caption without altering the size of that label, open up its properties and change the caption property there. Notice the label doesn't resize.
Now, those of you who know me know that I love a little VBA, a little programming. You don't need VBA to be a good Access developer, but it certainly helps. If you know just a couple of little commands here and there, you can really make your database a lot more powerful.
The caption property is no exception. You can manipulate that caption property in your VBA code. If you've never done any VBA before, go watch this. It's a primer about 20 minutes long; it will teach you everything you need to know to get started.
Let me show you a couple of cool tricks you can do with VBA with your captions. I cover this stuff in my advanced and developer classes. Let's go to the customer form again.
One thing you can do is change the form caption property based on the first and last name of the customer. Let's say you want to see what the first last name is. There's an event for the form called On Current. That happens when you move from record to record or when the first record loads. I have a whole separate video on the On Current event. If you want to watch it, I'll put a link down below.
Let's say when we move from record to record, or when this form opens up, I want this to say, "Customer: Richard Rost" or whoever. In the On Current event, we'll go right here, dot dot dot button. In the form current event, I'm going to say me.caption.
When you're in a form module - we're in a form module, form customer F - "me" is the form itself and "caption" is a property. So caption is a property of the customer F form, of pretty much every form. So me.caption, the caption of this form, equals "Customer:" and then maybe a dash, or let's do a colon. "Customer: " and first name and a space and last name.
Save that. Close the editor, close the form down, and reopen it. Look at that: "Customer - Richard Rost." As you move through your records, you'll see that. If you go to a blank record, there is no first name or last name, so it just says "Customer," and that's fine. You can check for nulls and you can do all kinds of other stuff.
You can change the captions of labels on the fly. You can change this in the After Update event so that it updates when you change these fields. You can change the captions of buttons, and I cover all this in my various courses. They're peppered throughout my developer courses, so I really can't point you to just one.
If you're a new user and you don't want to get into programming yet, Access Beginner 7 - I spend a lot of time dealing with the caption property - and in Access Advanced level two, when we start programming with macros, I show you how to make a button on your order form that you can flip between "Quotation" and "Invoice" dynamically. So if it's an invoice, it will say "Invoice," if it's a quote, it will say "Quotation."
I have tons of other tricks and tips I show you with VBA and the caption property throughout my developer classes. I cover it in about 15 different classes, a little bit here, a little bit there. If you want more information about this, you'll find links down below.
There you go, there is your fast tip for today. I hope you learned something and I'll see you next time.
Quiz
Q1. What does the caption property do for a field in a Microsoft Access table? A. It changes the color of the field in datasheet view B. It sets the display label or column header when the field is used in forms and queries C. It restricts data entry in that field D. It encrypts the field data for security
Q2. When might you find the caption property particularly useful in a table? A. To automatically enter today's date as a default value B. When you want to display a label with spaces instead of a field name without spaces C. To filter rows in queries D. To set up lookups between tables
Q3. What happens if you add a caption to a field in the table and then add that field to a form? A. The field will not appear on the form B. The caption becomes the label for the field on the form C. The field value becomes read-only D. The field automatically converts to a lookup field
Q4. What is the description property of a field typically used for in Access tables? A. To enforce referential integrity B. To specify a default value for the field C. To provide notes or instructions that appear in the status bar when the user tabs to the field in a form D. To change how data appears in datasheet view
Q5. Where will the content of the description property appear for the user? A. In the datasheet view as a new column B. In the status bar on the bottom of a form when the field is focused C. In the title bar of the database window D. As a tooltip when the mouse hovers over the field name
Q6. Which controls in an Access form typically have a caption property? A. Only forms B. Only buttons and combo boxes C. Labels, buttons, and the form itself D. Only text boxes
Q7. What effect does placing an ampersand (&) before a character in a label or button caption have? A. It makes the character bold B. It makes the character appear in uppercase C. It sets a keyboard shortcut (hot key) using Alt + that letter D. It encrypts the caption
Q8. If you want to change a label's caption without resizing its control on the form, what is the recommended method? A. Double-click the label and type directly B. Open the label's property sheet and change the caption property there C. Drag the label to a new location D. Add a new label and delete the old one
Q9. In VBA, how can you change the caption of a form to include the current record's first and last name? A. Use the form's On Activate event to set the caption B. Use the form's On Current event and set me.caption to "Customer: " & [FirstName] & " " & [LastName] C. Change the form's background color property D. Enable AutoCaption in the form properties
Q10. What is the result of putting an ampersand (&) in the caption property of a button, for example "&Close"? A. It makes the button text italic B. The button name becomes "and Close" C. Alt+C will activate that button when the form is open D. The caption appears in red
Q11. According to the video, why might an Access developer avoid using the caption property in table fields for queries? A. It reduces performance B. Query headers should show the actual field names for developer reference, not user-friendly captions C. It makes queries uneditable D. It removes formatting options from the query
Q12. Which event is commonly used in VBA to update a form's caption dynamically as the user moves between records? A. On Open B. On Load C. On Current D. On Click
Answers: 1-B; 2-B; 3-B; 4-C; 5-B; 6-C; 7-C; 8-B; 9-B; 10-C; 11-B; 12-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 video from the Access Learning Zone focuses on the caption property in Microsoft Access. Even if you already use the caption property, I have some extra techniques that you might not have seen before.
Many elements in Access, such as table fields, forms, and controls, come with a caption property, and how it behaves can depend on where you use it. For example, in a table, each field can have a caption property. Although I do not use this feature very often myself, setting a caption for a table field means that, when you add this field into a form, Access will use that caption as the label text. It also becomes the column header in any query you build. So, if you have a field named "FirstName" but you want it to display as "First Name," using the caption property can be a simple way to add the space. When you drag these fields onto a form or include them in a query, you'll see Access use the caption instead of the raw field name, saving you a little effort in naming labels or headers manually.
However, I personally do not use captions in tables for queries, because I believe that end users should not be working with queries directly. Queries are really for design and administrative use. I prefer to see the actual field names when creating queries, and I expect users to interact with forms and reports.
There is another property that often goes unnoticed: the description, which is also found in table fields. This property is optional and mainly intended for your own reference, but if you add a description, it will show up in the status bar whenever the user lands on that field in a form. This can be a helpful way to give users instructions or reminders about what should go into a particular field.
Now, forms offer even more flexibility with captions. Labels and buttons have caption properties, and the form object itself does too. You can specify any text you want as a caption, and this will appear as the text on the label, button, or the title bar of the form, depending on where you set it.
Here's a useful trick: When you have a label that is attached to a text box, you can use an ampersand in the caption to create a keyboard shortcut. For example, if you set the caption to "&Name," Access will underline the "N," and pressing Alt+N will jump the cursor to that field. This feature can make form navigation faster, especially if there are several fields users need to reach quickly. The same shortcut system works for buttons, too. Adding an ampersand lets someone activate a button with an Alt key combination.
Another detail to be aware of is how Access handles resizing labels when you change their captions. If you adjust the caption directly in the form designer by typing on the label, Access will try to auto-size the label, which might not be what you want. To avoid this, make changes to the caption property using the property sheet instead. This way, the label size remains unchanged.
For those interested in programming with VBA, the caption property is quite useful. You can update captions dynamically based on your data or responses to events. For example, you could update the form's caption to display the current customer's name every time you move between records. This involves using the On Current event for the form, where you can set the caption property in code. As you navigate through customer records, the form title will change to show the current customer's name. If the record is blank, the title can adjust accordingly.
You can apply the same principle to labels and buttons, changing their captions on the fly to match the data in your form or to reflect user actions and choices. I cover lots of these practical examples in my advanced and developer-level Access classes. For new users not ready for programming, I show how to work with captions in detail in Access Beginner level 7. In my more advanced courses, like Access Advanced level 2, I explain how to use macros to alter captions dynamically. For example, you can set up a button on an order form to toggle its caption between "Quotation" and "Invoice" based on the context.
I offer many more tips and tricks for working with captions—using both standard Access tools and VBA—throughout my various courses. You will find a complete video tutorial with step-by-step instructions for everything I discussed here on my website at the link below.
Live long and prosper, my friends.
Topic List
Understanding the Caption property in Access tables, forms, and controls Setting the Caption property for table fields to customize form labels and query column headers Demonstrating how Caption property affects form and query display Using the Description property to display status bar text in forms Explaining how Description property appears in form status bars Setting Caption properties for labels, buttons, and forms Creating keyboard shortcut hotkeys with ampersands in captions Assigning hotkeys to form buttons and labels Editing Caption property directly vs. in property sheet to control label resizing Changing form Caption property dynamically with VBA Using the On Current event to update form Caption with record data Updating control captions dynamically with VBA code
|