=> Control Label

  • Thread starter Jonathan Parminter
  • Start date
J

Jonathan Parminter

Hi, I'm wondering whether it is possible to identify a
control's associated label at run time? It must be stored
in some property otherwise, in design view, selecting a
control would not also select its associated control.

I want to set up loop through a form's controls and if
required display the textbox/combobox associated
label.caption

The alternative I can use is the control's tag property.
But what if I change a control's associated label.caption?

Thanks
Jonathan
 
D

Dirk Goldgar

Jonathan Parminter said:
Hi, I'm wondering whether it is possible to identify a
control's associated label at run time? It must be stored
in some property otherwise, in design view, selecting a
control would not also select its associated control.

I want to set up loop through a form's controls and if
required display the textbox/combobox associated
label.caption

The alternative I can use is the control's tag property.
But what if I change a control's associated label.caption?

If the label is actually attached to the control (as far as Access is
concerned), it will be in the "owner" control's Controls collection.
For a text box, list box, or combo box, I believe there is never more
than one control in the control's Controls collection -- its attached
label. For an option group frame, the frame's own label, the option
controls that are in the group, and their labels, are all members of the
frame's Controls collection. That makes figuring out which label
actually belongs to the frame trickier. But if all you're interested in
is text, list, and combo boxes, you could use code along these lines:

'*** AIR CODE ***
Dim ctl As Control

For each ctl In Me.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox, acListBox
If ctl.Controls.Count > 0 Then
Debug.Print ctl.Name, ctl.Controls(0).Caption
End If
Case Else
' ignore
End Select
Next ctl
 

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