How to refer to the label of a subform control

S

ScardyBob

I'm having trouble referring to the Caption property of a label
attached to a subform control. Essentially what I am trying to do is
search a Yes/No Field in a subform and if no Yes values are found, a
message box appears informing the user which subform needs to have at
least one Yes selected. I've got the search part working, but I can't
figure out how to refer to the caption of the label attached to the
subform control.
I've tried many different things including,

Forms!MainForm!SubFormControl.Controls(0).Caption

which usually works for other types of controls (textbox, combobox,
etc.), but in this case it refers to the first control in the subform,
not the subform control itself.

Thanks in Advance,
Mike
 
J

Jeff Boyce

Have you tried

Forms!YourForm!YourSubformControl.Form!YourLabelControl.Caption

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
M

Marshall Barton

ScardyBob said:
I'm having trouble referring to the Caption property of a label
attached to a subform control. Essentially what I am trying to do is
search a Yes/No Field in a subform and if no Yes values are found, a
message box appears informing the user which subform needs to have at
least one Yes selected. I've got the search part working, but I can't
figure out how to refer to the caption of the label attached to the
subform control.
I've tried many different things including,

Forms!MainForm!SubFormControl.Controls(0).Caption

which usually works for other types of controls (textbox, combobox,
etc.), but in this case it refers to the first control in the subform,
not the subform control itself.


This a hole in the default behavior for subform controls.
They should have required the .Form property from the
beginning, but when thay made it optional, it meant that you
can not reference the Controls collection of a subform
control by using the subform controls name.

After a lot of poking around, I stumbled across an
alternative construct that worked for me. The requirement
is that the focus be on either the subform control or a
control in the subform. From the main form:
Me.SubFormControl.SetFocus
MsgBox Me.ActiveControl.Controls(0).Caption
 
S

ScardyBob

Worked like a charm!

Thanks for the help,
Mike

Marshall said:
This a hole in the default behavior for subform controls.
They should have required the .Form property from the
beginning, but when thay made it optional, it meant that you
can not reference the Controls collection of a subform
control by using the subform controls name.

After a lot of poking around, I stumbled across an
alternative construct that worked for me. The requirement
is that the focus be on either the subform control or a
control in the subform. From the main form:
Me.SubFormControl.SetFocus
MsgBox Me.ActiveControl.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