Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

on a form, refer to a control's label 1

Status
Not open for further replies.

Weebairnes

Programmer
Dec 23, 2003
25
US
I have a form with a text box control named "txtName." Associated with this text box control is the label, "lbl1". The caption property of lbl1 is, "Enter your name:"

I can refer the label in VBA as me.lbl1. From here I can change format properties, the caption, etc.

I can refer to the text box as me.txtName and then get to a whole host of properties. Its fontsize, controlsource, backcolor, etc. However, regarding label properties for the control txtName, all I see is three properties: LabelAlign, LabelX, LabelY.

Now, lets say I don't know the name of the associated label. Is there a way to change or get the label caption from lbl1 if I am currently accessing me.txtName?

 
you can use the following code
Code:
Me.txtName.Controls(0).Caption = "What Ever:"
 
Thanks! You're free impartation of pertinent knowledge to resolve the syntactical discombobulation I was facing has saved the day.

Question.

How does the "Controls(0)" portion work? What does it mean in association with the other control?
 

How does the "Controls(0)" portion work?

Every control that could have controls attached to it (Example: a Text box or combo box can have a label a form has controls on it) has a Controls property which is a collection of controls affiliated to the control.

All collections in access start they're count from 0 not from 1.


What does it mean in association with the other control?

A label is a child of the Control it represents.
 
Many thanks. I never realized that the a label is a child of the Control it represents.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top