finding a control in a sub form

  • Thread starter Thread starter Lasse T
  • Start date Start date
L

Lasse T

Hello !!
I have a code that updates a value in another forms sub form. How can i get
the code to locate the controller?
If I open the subform without the main form the code works but if i open the
main form and with that, the sub form I get an error saying that the form
cannot be found.

I have very little experience in VBA so if it can be done without too much
code I would be happy.

Thanks in advance.

Lasse T
-----------
 
Hi Lasse,

You must reference the control via the subform control on the main form:

forms!frmMain.SubFormCtl.form.Text1=99

Replace 'frmMain' with the name of the Main form

Replace 'SubFormCtl' with the name of the subform control on the Main form.
Note that this is not necessarily the same name as the name of the form
object that you see in the database window. To be sure, select the subform
control, then look at the Name property under the Other tab. This is the
name that should be used in all references to the subform control.

Replace 'Text1' with the name of the control on the subform.
 
Thank you for the fast answer. One , probably silly, question remains. Where
do I type the code?
the only place I can think of are the in the event of the button that
updates the racord in the subform. Is this right?

Lasse
-----------

Sandra Daigle said:
Hi Lasse,

You must reference the control via the subform control on the main form:

forms!frmMain.SubFormCtl.form.Text1=99

Replace 'frmMain' with the name of the Main form

Replace 'SubFormCtl' with the name of the subform control on the Main form.
Note that this is not necessarily the same name as the name of the form
object that you see in the database window. To be sure, select the subform
control, then look at the Name property under the Other tab. This is the
name that should be used in all references to the subform control.

Replace 'Text1' with the name of the control on the subform.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Lasse said:
Hello !!
I have a code that updates a value in another forms sub form. How can i
get the code to locate the controller?
If I open the subform without the main form the code works but if i open
the main form and with that, the sub form I get an error saying that the
form cannot be found.

I have very little experience in VBA so if it can be done without too much
code I would be happy.

Thanks in advance.

Lasse T
-----------
 
Sorry, I didn't specify this because I wasn't sure how you wanted it to get
called. If you are using a button then you are correct, the code would go in
the Click event of the button.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Lasse said:
Thank you for the fast answer. One , probably silly, question remains.
Where do I type the code?
the only place I can think of are the in the event of the button that
updates the racord in the subform. Is this right?

Lasse
-----------

Sandra Daigle said:
Hi Lasse,

You must reference the control via the subform control on the main form:

forms!frmMain.SubFormCtl.form.Text1=99

Replace 'frmMain' with the name of the Main form

Replace 'SubFormCtl' with the name of the subform control on the Main
form. Note that this is not necessarily the same name as the name of the
form object that you see in the database window. To be sure, select the
subform control, then look at the Name property under the Other tab.
This is the name that should be used in all references to the subform
control.

Replace 'Text1' with the name of the control on the subform.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Lasse said:
Hello !!
I have a code that updates a value in another forms sub form. How can i
get the code to locate the controller?
If I open the subform without the main form the code works but if i open
the main form and with that, the sub form I get an error saying that the
form cannot be found.

I have very little experience in VBA so if it can be done without too
much code I would be happy.

Thanks in advance.

Lasse T
-----------
 
Thank you very much.
It´s working perfect now.

Lasse T
----------------

Sandra Daigle said:
Sorry, I didn't specify this because I wasn't sure how you wanted it to get
called. If you are using a button then you are correct, the code would go in
the Click event of the button.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Lasse said:
Thank you for the fast answer. One , probably silly, question remains.
Where do I type the code?
the only place I can think of are the in the event of the button that
updates the racord in the subform. Is this right?

Lasse
-----------

Sandra Daigle said:
Hi Lasse,

You must reference the control via the subform control on the main form:

forms!frmMain.SubFormCtl.form.Text1=99

Replace 'frmMain' with the name of the Main form

Replace 'SubFormCtl' with the name of the subform control on the Main
form. Note that this is not necessarily the same name as the name of the
form object that you see in the database window. To be sure, select the
subform control, then look at the Name property under the Other tab.
This is the name that should be used in all references to the subform
control.

Replace 'Text1' with the name of the control on the subform.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

Lasse T wrote:
Hello !!
I have a code that updates a value in another forms sub form. How can i
get the code to locate the controller?
If I open the subform without the main form the code works but if i open
the main form and with that, the sub form I get an error saying that the
form cannot be found.

I have very little experience in VBA so if it can be done without too
much code I would be happy.

Thanks in advance.

Lasse T
-----------
 
Back
Top