Avatar of kentgorrell
 asked on

Get the name of a control's label in vba

At design time I loop through my controls in VBA to apply naming conventions.

I want to rename my labels as "lbl" & [Control source of the control the label is attached to].
To do this I either need to find the name of the control the label is attached to or, visa versa, the name of the label attached to each text or combo box.

Is there a property of the label or the txt/cbo box that will do this? I can't see one. Or is there another method?
Microsoft Access

Avatar of undefined
Last Comment

8/22/2022 - Mon
Graham Mandeno

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

.Controls(0) was what I needed. Thank you.

Can there be more than one control (anything other then a label) in a text (or combo) box's controls collection?
Graham Mandeno

I'm not sure - I've never seen more than one for a text or combo box, and I can't see how there could be more.

Of course, some other objects such as a tab control or a form section can have multiple members in this collection.


Thanks Graham, I can't think of anything other than a label.

Tab controls' Intellisense doesn't list the Controls collection but it's there.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Dale Fye

You can also use the following syntax to tet the name (or any other property) of the control associated with any label (or any other control for that matter)


If the control is a label, and it is associated with another control, you will get the controlname.  If it is a label that is not associated with another control, you will get the form name (as you would with any of the textbox, lists, combo, checkbox, ... other controls).

One small adjustment to prevent controls in the footer replacing the controls with the same tab index as the ones in the detail section.
Line 2 should be -

For Each ctl in frm.Detail.Controls