Referrring to SubForm Controls

  • Thread starter Thread starter chris1 via AccessMonster.com
  • Start date 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!
 
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
 
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!
 
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.
 
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!
 
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!
 
Back
Top