John W. Colby
jwcolby at colbyconsulting.com
Wed Mar 30 20:30:07 CST 2005
The form's control collection allows you to find the control using the name as follows: Me.controls("CtlName") where "CtlName" is the name of your control. This syntax only works from within the form's module. The text box's control collection has a single control in it which is the label. Thus MyTxtBox.Controls(0) will return the label for MyTxtBox. Remember that a label can be deleted thus a text box MAY not have a label, make sure you use On Error Resume Next to handle such issues. Thus something like: Dim txt as TextBox Dim lbl as Label Set txt = me.Controls("CtlName") On error resume next Set lbl = txt.Controls(0) A shortcut to directly reference the text box control, and then its label would be: me.controls("CltName").Controls(0) Alternately you could use: Forms("FrmName").Controls("CtlName").Controls(0) This version assumes the form is loaded and will work from anywhere, not just from the form's module. Be careful though if you try to apply this syntax to other controls. Some controls can have more than one control in its control collection (option groups for example), and while the label is generally control(0), it MAY not be, in particular if the label was deleted, then added back in again. John W. Colby www.ColbyConsulting.com Contribute your unused CPU cycles to a good cause: http://folding.stanford.edu/ -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gregg Sent: Wednesday, March 30, 2005 7:07 PM To: Access Developers discussion and problem solving Subject: [AccessD] Find Label text attached to Text Box If you have a Text Box with an attached Label is there some way to find the Label Text when you only know the Text Box Name? -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com