Find label associated with textbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way, in code, to determine the label that is associated with a
specific text box, checkbox, combo box, etc.?

The idea would be to loop through the controls in a form and be able to
identify the label that is associated with one of these controls.

Thanks for any help on this, Herb
 
Herb said:
Is there a way, in code, to determine the label that is associated
with a specific text box, checkbox, combo box, etc.?

The idea would be to loop through the controls in a form and be able
to identify the label that is associated with one of these controls.

Thanks for any help on this, Herb

Each control with an attached label actaully has its own Controls collection
with the label being the first member. So...

Me.TextBoxName.Controls(0)

....should give a reference to the label attached to TextBoxName.
 
It's actually easier to do the reverse: if a label is linked to a specific
control, then Forms("NameOfForm").Controls("NameOfLabel").Parent.Name will
return the name of that control, whereas it will return the name of the form
is the label isn't linked to a control.
 
This is usually done using the label's Tag property.
If a label were associated with a text control called City, it could be given a Tag of
"City"
Then you're control loop could look for that value...
 
Rick Brandt said:
Each control with an attached label actaully has its own Controls
collection with the label being the first member. So...

Me.TextBoxName.Controls(0)

...should give a reference to the label attached to TextBoxName.

I knew it was something like that, but my mind went blank when answering!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top