If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: programmatically find a control's label

Originally posted by jpshay
Is there a way to refer to a control's label if you only know what the control name is?

For example, using VBA, and cycling through all controls on a form, can you get the caption from the associated label - when you don't know what the name of the label is?

I don't know if it's possible, but I think you might solve the problem just by assigning structured names to the controls.
If you have a control (let's say a textfield with its label)
If you name the textfield 'txtMyTextField' and the label 'lblMyLabel' than it can't be so difficult to understand which label belongs to which textfield.

I do label option groups, text boxes combo boxes with labels because of the need to reefer to them with code. But labeling their labels would be twice the amount of work. With small database, no big deal; with multiple databases, multiple forms, with 50 to 100 controls per for, it becomes onerous.

So, is there a way with VBA, to refer to the label of the current control?

John
This is the day the Lord has made, I will rejoice and be glad in it.

Lets say I have a form with a text box control named "txtName." Associated with this text box control is the label, "lbl1"

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

I can refer to the text box in VBA as me.txtName and then get to a whole host of properties. Its fontsize, controlsource, backcolor, etc.
Regarding label properties for the control, 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?

John
This is the day the Lord has made, I will rejoice and be glad in it.