Naming a subform from a main form

J

jimphilly

I'm having a heck of a time getting to a control on a sub form from a main
form. I use the following convention

Forms![frm MAIN_FORM]![frm SUB_FORM]![CONTROL_NAME]

However when I run the code, I get an error message informing me Access
cannot find the field named [frm SUB_FORM]. Then I tried taking the mainform
out of the line leaving me with
Forms![frm SUB-FORM]![CONTROL_NAME]

Then the message reads can find find the form named frm subform. As far as
I can tell the subform is opened. I can see it.

I'm baffled. Can you help me?
 
S

Steve

Common problem!!

Open your main form in design view. Select the border around the subform.
This is the subform control. Open Properties and Go to the Other tab. Look
at the name property for the subform control. This is what you use in your
expression NOT the name of the subform! Let's say the name is "Jimphily".
The syntax to refer to the control, Control_Name, on your subform is:
Forms![frm MAIN_FORM]!Jimphily.Form![CONTROL_NAME]

By the way, it takes two steps to set focus to a control on a subform from
the main form. You must forst set focus on the subform control and then set
focus on the control on the subform:
Me!Jimphily.SetFocus
Me!Jimphilly.Form![Control_Name].SetFocus

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)
 
M

Marshall Barton

jimphilly said:
I'm having a heck of a time getting to a control on a sub form from a main
form. I use the following convention

Forms![frm MAIN_FORM]![frm SUB_FORM]![CONTROL_NAME]

However when I run the code, I get an error message informing me Access
cannot find the field named [frm SUB_FORM].


Forms![frm MAIN_FORM]![frm SUB_FORM].FORM![CONTROL_NAME]

Note that [frm SUB_FORM] needs to be the name of the subform
control on the main form. The name of the form object being
displayed in the subform control is irrelevant.
 

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