Reference a field on subform from main form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I would like to get support on how to get the sum of a field from a sub form
to be displayed on the main form.

I have tried this syntax =sum([Expenditure]) but I am getting an error.

Please help.

Rgds.
 
Simply put a control in the sub-forms report footer..

eg, the control could be called

txtExpSum

For the data expression of this contorl, you would use

=sum([Expenditure])

Test the above...and you should see the sum of that field in the bottom of
your sub-form.

Make sure you have the above working. Then, and ONLY then can you start on
placing/using/showing this value on the main
form part.

Now, in your main form, you can use the above total values such as

=([NameOFSubFormContorl].[Form].[txtExpSum])
 
Thanks for your promt response.

I have tried your suggestion on my subform and it is working perfectly.
However when I tried this syntax =([Exp SubForm].[Form].[txtSumExp]) on the
main form it does not work. I am getting the error message #Name?.
I realise after running the form that some of the square brackets are taken
out with this remaining =([Exp SubForm].Form.txtSumExp).

Please advise on what needs to be done.

Rgds.
 
Alylia said:
Thanks for your promt response.

I have tried your suggestion on my subform and it is working perfectly.
However when I tried this syntax =([Exp SubForm].[Form].[txtSumExp]) on
the
main form it does not work. I am getting the error message #Name?.
I realise after running the form that some of the square brackets are
taken
out with this remaining =([Exp SubForm].Form.txtSumExp).

Please advise on what needs to be done.

Remember, you can place a standard text control on a form called "zoo", and
set the data source of that text box
to

LastName.

In other words, the name of the control on the form is NOT related to the
actual data source that it is attached to. MOST of the time we do name the
control the same as the underlying field data source.

A control on a form is just that, a control with a name. A sub-form control
is the same concept, and the name of the sub-form control is often different
then what sub-form the control displays...

So, you don't use the name of the sub-from in the above expression, but the
actual name you used for the sub-form control. They are *usually* the same,
but they don't have to be.....

You try some test code on the main form. Place a button on the main part of
the form. The code behind this test button could be

msgbox me.exp_subform.form.txtSumExp

what does inteli -sense give for the control name of your sub form.
Remember, this name is NOT necessary the same name as the actual sub-form
used for that control...(they likely are the same...but, don't have to be).

So, try making that msgbox command work behind a test button. Once you get
that working, then
you can select the correct values for your expression....

As a side note, the wizard often puts in a space for the control name....I
would suggest DO NOT use spaces in field names, form names, query names, and
especially control names on a form. Spaces in names of things are a royal
pain, and are often the cause of much suffering...
 
Thanks for the great support it has now worked.

Rgds.

Albert D. Kallal said:
Alylia said:
Thanks for your promt response.

I have tried your suggestion on my subform and it is working perfectly.
However when I tried this syntax =([Exp SubForm].[Form].[txtSumExp]) on
the
main form it does not work. I am getting the error message #Name?.
I realise after running the form that some of the square brackets are
taken
out with this remaining =([Exp SubForm].Form.txtSumExp).

Please advise on what needs to be done.

Remember, you can place a standard text control on a form called "zoo", and
set the data source of that text box
to

LastName.

In other words, the name of the control on the form is NOT related to the
actual data source that it is attached to. MOST of the time we do name the
control the same as the underlying field data source.

A control on a form is just that, a control with a name. A sub-form control
is the same concept, and the name of the sub-form control is often different
then what sub-form the control displays...

So, you don't use the name of the sub-from in the above expression, but the
actual name you used for the sub-form control. They are *usually* the same,
but they don't have to be.....

You try some test code on the main form. Place a button on the main part of
the form. The code behind this test button could be

msgbox me.exp_subform.form.txtSumExp

what does inteli -sense give for the control name of your sub form.
Remember, this name is NOT necessary the same name as the actual sub-form
used for that control...(they likely are the same...but, don't have to be).

So, try making that msgbox command work behind a test button. Once you get
that working, then
you can select the correct values for your expression....

As a side note, the wizard often puts in a space for the control name....I
would suggest DO NOT use spaces in field names, form names, query names, and
especially control names on a form. Spaces in names of things are a royal
pain, and are often the cause of much suffering...
 

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

Back
Top