VB-  form (properties)tag

suneel_manohar used Ask the Experts™
what is "tag" in the VB - project - form (properties) and what are its applications?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006
Hello Suneel_manohar,

That property is there for you to store whatever information you want! Some applications use that property to store metadata for the field to try to automate some processes. For instance, you could store a little information as to how the field is supposed to be validated, its description, related field on a database, etc. For instance, if bound controls is not an option you want to consider, you may want to use this property to store the table name and field name that the control is linked to. That way, you could loop all the controls in your form and prepare a SQL string ready to be sent to the database. I am not suggesting you do this, I am just giving you an idea as to where this property may be used.

It is a free use String property that is available for each control in your form.

you use it like

Dim cntlControl As Control
For Each cntlControl In Me.Controls
   If cntlControl.Tag = "MyTag" Then
     cntlControl.Visible = False
   End If
Next cntlControl

The tag property is a string to be used however you please (as bruintje indicated).  It's uses are as varied as your imagination .  Here are some more common uses:

1) To store a record identifier that is in the form of a string
2) To apply a filter on the controls you want to validate when you write a global filter routine.  So some fields that MUST be present will have a Tag property of "Required" while optional fields will not.
3) To apply a filter on the controls you want to use as a sort of group.  For instance, if you want to treat 3 textboxes on the form as applying to the current User info the next 2 apply to secutiry permissions and so on.

It is generally not considered good programming practice anymore to use the Tag property anymore because it is usually set in design mode, thereby making it a "Magic Selector/Filter" of controls, however, it does have it's uses.

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points for bruintje  .

Please leave any comments here within the next seven days.
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial