Find the label corresponding to a textbox in a form

E

Etienne Bar

Hi,

I need to find in a form all labels corresponding to textboxes and change
their caption.
For reasons too complex to explain here (the labels are stored in a separate
table for easy changes and translations), i can't use the caption property
in the tables or queries...

So, i use this code :

Sub Test_Form(MyForm As Form)
Dim ctl As Control ' The textbox
Dim ctlLabel As Control

For Each ctl In MyForm.Controls
If ctl.ControlType = acTextBox Then
' set ctlLabel = the label corresponding to the control <== Here
what's i'am looking for !
' TheLabel.caption = my new label
End If
Next ctl

End Sub

my question is : what is the good way to find the label corresponding to ctl
?

Thanks for your answers and excuse me for my poor english...
 
A

Allen Browne

If a control has an attached label, you can refer to it as Controls(0), e.g.
Debug.Print ctl.Controls(0).Caption
 

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