Access A SubForm

  • Thread starter Thread starter Dickie
  • Start date Start date
D

Dickie

I have created a Form with a embedded subform. I'm trying to run some code
which updates a field on the sub form. BUT when I run the code with the main
form open it cannot access the subform field, it keeps coming up with a
debug error saying "cannot find field".

If I run the same code with just the sub form open, the code works fine.

How do I address fields in a subform.

Thanx
 
The syntax for accessing a subForm control from the main
form is
Me!subFormControlName.Form!controlName

I am guessing that your code is trying to reference the
subform using its 'form' name and not by the 'control' name
it is known by on the main form.

Hope This Helps
Gerald Stanley MCSD
 
A subform is not open by itself - it is only open indirectly through the
subform control on the main form. So to reference a control on the subform,
you must also reference the subform control. If the subform control is named
sfrmSub1 and the control on the subform is named txtMyControl then from the
class module of the main form the correct reference to this control would
be:

'to assign a value

me.sfrmSub1.form.txtMyControl=123

Note that 'sfrmSub1' must be the name of the subform control on the main
form. This is not necessarily the same as the name of the form object that
is referenced in the ControlSource of the subform control. To be sure, open
the main form and click once on the subform then check the name property
under the Other tab. Whatever you find there is what belongs in place of
sfrmSub1.
 
Thanx, BUT
My main form is Mainform1, my sub form is SubForm1.

The control on the subform is called cmbBox1.

If I use Me![SubForm1].Form![cmbBox1]
I get the error invalide use of the keyword Me.
 
In which case the code cannot be running from the form.
The syntax for referencing controls from code outside the
form is
Forms!formName!subFormControlName.Form!controlName

Try
Forms!Mainform1![SubForm1].Form![cmbBox1]

Hope This Helps
Gerald Stanley MCSD
-----Original Message-----
Thanx, BUT
My main form is Mainform1, my sub form is SubForm1.

The control on the subform is called cmbBox1.

If I use Me![SubForm1].Form![cmbBox1]
I get the error invalide use of the keyword Me.


The syntax for accessing a subForm control from the main
form is
Me!subFormControlName.Form!controlName

I am guessing that your code is trying to reference the
subform using its 'form' name and not by the 'control' name
it is known by on the main form.

Hope This Helps
Gerald Stanley MCSD


.
 
Thanx.

Nice and easy when u know how...!

Gerald Stanley said:
In which case the code cannot be running from the form.
The syntax for referencing controls from code outside the
form is
Forms!formName!subFormControlName.Form!controlName

Try
Forms!Mainform1![SubForm1].Form![cmbBox1]

Hope This Helps
Gerald Stanley MCSD
-----Original Message-----
Thanx, BUT
My main form is Mainform1, my sub form is SubForm1.

The control on the subform is called cmbBox1.

If I use Me![SubForm1].Form![cmbBox1]
I get the error invalide use of the keyword Me.


The syntax for accessing a subForm control from the main
form is
Me!subFormControlName.Form!controlName

I am guessing that your code is trying to reference the
subform using its 'form' name and not by the 'control' name
it is known by on the main form.

Hope This Helps
Gerald Stanley MCSD
-----Original Message-----
I have created a Form with a embedded subform. I'm trying
to run some code
which updates a field on the sub form. BUT when I run the
code with the main
form open it cannot access the subform field, it keeps
coming up with a
debug error saying "cannot find field".

If I run the same code with just the sub form open, the
code works fine.

How do I address fields in a subform.

Thanx


.


.
 
Back
Top