Labels and Associated Controls.

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

Guest

Hi,

Is there any way using VBA that I can determine the label that is associated
with a specific control? I can't see any control property that would store
the label, but MS Access 2003 has the facility - in form design view - to
associate a label with a specific control.

All I want to do is to pick up the caption from the label associated with a
specific control - if there is a label associated with it. I can then use
this value in message boxes etc. displayed to the user, instead of the name
of the control which will be prefixed and not as meaningful to them.

Any ideas?

Many thanks,

Stuart
 
If there's a label linked to the control, you should be able to refer to the
caption of that label as Me.MyControl.Controls(0).Caption (where MyControl
is the name of the control to which the label is linked).

If there's no label, then Me.MyControl.Controls.Count should be 0.
 
The attached label is the first (and only) member of the Controls collection
of the control.

So the caption of the label attached to the text box named txtCity is:
[txtCity].Controls(0).Caption
 
Doug / Allen,

You two are gentlemen! Exactly what I wanted and needed to know. Two ticks
appearing soon.

Many thanks,

Stuart
 
Stuart said:
Is there any way using VBA that I can determine the label that is associated
with a specific control? I can't see any control property that would store
the label, but MS Access 2003 has the facility - in form design view - to
associate a label with a specific control.

All I want to do is to pick up the caption from the label associated with a
specific control - if there is a label associated with it. I can then use
this value in message boxes etc. displayed to the user, instead of the name
of the control which will be prefixed and not as meaningful to them.


If Me.controlname.Controls.Count > 0 Then
thecaption = Me.controlname.Controls(0).Caption
Else
'no attached label
End If
 
I know this thread was posted a while ago but I wanted to thank you guys for
the excellent job you do by answering our questions here. I had this same
question today and I was able to find the answer here very quickly. Thanks
again and keep doing this great work!!
 
Back
Top