Find label associated with textbox

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
 
R

Rick Brandt

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.
 
D

Douglas J. Steele

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.
 
A

Al Campagna

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...
 
D

Douglas J. Steele

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!
 
D

Douglas J. Steele

Rick Brandt said:
Hey, I just learned it myself in these groups a few months ago :)

The sad part is it might of been me you learned it from! <g>
 

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

Top