Referrring to SubForm Controls

  • Thread starter chris1 via AccessMonster.com
  • Start date
C

chris1 via AccessMonster.com

I have a 3 forms, MainForm, SubForm1 and SubForm2. From SubForm2, I would
like to refer to a control on SubForm1 through VBA. I have the following
syntax:

Forms![MainForm]![SubForm1]![ControlName].Value


Could someone please provide me the correct syntax. Thank you in advance!
 
K

Klatuu

The first thing to consider is your naming convention. In what you are
trying to do, you do not use the name of the form that is subform, but to the
name of the subform control on the main form. Then when in a subform, you
refer to the main form as Parent. For example,

Me.Parent......

So be sure you use the subform control name and try it this way:

Me.Parent![SubFormControl1].Form![ControlName].Value
 
C

chris1 via AccessMonster.com

Does SubFormControl1 refer to to SubForm1? Could you give the syntax without
using the parent ?
I am a little confused on what you were trying to say!
 
K

Klatuu

Using Parent is the proper syntax.

Open your form in design view.
Click on the where the sub form is.
It will be a subform control. The subform has a name like any other object.
It may or may not be the same name as the form being used as the subform.
The Source Object property of the subform control contains the name of the
form that is attached as a subform.

So there are two names, one for the subform control and one for the subform.
They can (but to avoid confusion, should not be) the same.

In your code you want to refer to the name of the subform control. So the
correct syntax is

Me.Parent![SubFormControl1].Form![ControlName].Value


Me.... references the active form
Parent... The main form
SubFormControl1... The name of the subform control on the main form.
Form... refers to the subform control source object
ControlName... The name of the control on the subform control's form.

Value is optional, you don't really need it. It is the default property.
 
C

chris1 via AccessMonster.com

Thank you, it worked... I hope this helps others as well!!!

Using Parent is the proper syntax.

Open your form in design view.
Click on the where the sub form is.
It will be a subform control. The subform has a name like any other object.
It may or may not be the same name as the form being used as the subform.
The Source Object property of the subform control contains the name of the
form that is attached as a subform.

So there are two names, one for the subform control and one for the subform.
They can (but to avoid confusion, should not be) the same.

In your code you want to refer to the name of the subform control. So the
correct syntax is

Me.Parent![SubFormControl1].Form![ControlName].Value

Me.... references the active form
Parent... The main form
SubFormControl1... The name of the subform control on the main form.
Form... refers to the subform control source object
ControlName... The name of the control on the subform control's form.

Value is optional, you don't really need it. It is the default property.
Does SubFormControl1 refer to to SubForm1? Could you give the syntax without
using the parent ?
I am a little confused on what you were trying to say!
 
K

Klatuu

Great!
If you want it to help others, rate the response. People will look for
answers questions (green check mark) when they are searching.
--
Dave Hargis, Microsoft Access MVP


chris1 via AccessMonster.com said:
Thank you, it worked... I hope this helps others as well!!!

Using Parent is the proper syntax.

Open your form in design view.
Click on the where the sub form is.
It will be a subform control. The subform has a name like any other object.
It may or may not be the same name as the form being used as the subform.
The Source Object property of the subform control contains the name of the
form that is attached as a subform.

So there are two names, one for the subform control and one for the subform.
They can (but to avoid confusion, should not be) the same.

In your code you want to refer to the name of the subform control. So the
correct syntax is

Me.Parent![SubFormControl1].Form![ControlName].Value

Me.... references the active form
Parent... The main form
SubFormControl1... The name of the subform control on the main form.
Form... refers to the subform control source object
ControlName... The name of the control on the subform control's form.

Value is optional, you don't really need it. It is the default property.
Does SubFormControl1 refer to to SubForm1? Could you give the syntax without
using the parent ?
I am a little confused on what you were trying to say!
 

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