Applies ToAccess for Microsoft 365 Access 2024 Access 2021 Access 2019 Access 2016

Applies to

BoundObjectFrame Object

Image Object

OptionGroup Object

SubForm Object

CheckBox Object

Label Object

Page Object

TabControl Collection

ComboBox Object

Line Object

PageBreak Object

TextBox Object

CommandButton Object

ListBox Object

Rectangle Object

ToggleButton Object

CustomControl Object

ObjectFrame Object

Report Object

Form Object

OptionButton Object

Section Object

Stores extra information about a form, report, data access page, section, or control needed by an Access application. Read/write String.

expression.Tag

expression Required. An expression that returns one of the objects in the Applies To list.

Remarks

You can enter a string expression up to 2048 characters long. The default setting is a zero-length string (" ").

You can set this property by using the object's property sheet, a macro, or Visual Basic for Applications (VBA) code.

Unlike other properties, the Tag property setting doesn't affect any of an object's attributes.

You can use this property to assign an identification string to an object without affecting any of its other property settings or causing other side effects. The Tag property is useful when you need to check the identity of a form, report, data access page, section, or control that is passed as a variable to a procedure.

Example

The following example uses the Tag property to display custom messages about controls on a form. When a control has the focus, descriptive text is displayed in a label control called lblMessage. You specify the text for the message by setting the Tag property for each control to a short text string. When a control receives the focus, its Tag property is assigned to the label control's Caption property. This example displays the descriptive text for a text box named txtDescription and a command button named cmdButton on a form.

Sub Form_Load()
    Dim frmMessageForm As Form
    Set frmMessageForm = Forms!Form1
    frmMessageForm!lblMessage.Caption = "" ' Clear text.
    frmMessageForm!txtDescription.Tag = _
        "Help text for the text box."
    frmMessageForm!cmdButton.Tag = _
        "Help text for the command button."
End Sub
Sub txtDescription_GotFocus()
    ' Tag property setting as caption.
    Me!lblMessage.Caption = Me!txtDescription.Tag
End Sub
Sub txtDescription_LostFocus()
    Me!lblMessage.Caption = ""
End Sub
Sub cmdButton_GotFocus()
    ' Tag property setting as caption.
    Me!lblMessage.Caption = Me!cmdButton.Tag         
End Sub
Sub cmdButton_LostFocus()
    Me.lblMessage.Caption = " "
End Sub

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.