How to add calculated field to forms

J

Jack

Jack said:
I wold like to add a calculated field to a master/sub form. I would like to put a calculated field on the master that will give me the sum of Amount due and Amount received fields on the sub form. And will update when I enter a new or change a record on the sub form.
 
J

John W. Vinson

I wold like to add a calculated field to a master/sub form.

Create a new textbox on the form.
Set its Control Source to

=[txtX] + [txtY]

or whatever calculation you want to use.

Your question is awfully vague, so you're getting an awfully vague answer.
 
K

KenSheridan via AccessMonster.com

When you say one text box with the sum of both fields do you mean you want
the sum of all amounts due + the sum of all amounts received? I'll assume so,
but if not hopefully the following will give you the general idea and you'll
be able to modify it to suit your requirements.

First you need to add a text box to the subform, txtTotalAmount say, with a
ControlSource property of:

=Sum([Amount Due])+Sum([AmountReceived])

Set its Visible property to False (No) to hide it.

Add another text box to the parent form with a ContolSource of:

=[YourSubformControl].Form.[txtTotalAmount]

where YourSubformControl is the name of the control in the parent form which
houses the subform, not the name of its underlying form object; unless both
have the same name of course. It should recalculate automatically, but if
not put the following in the subform's AfterUpdate event procedure:

Me.Parent.Recalc

Ken Sheridan
Stafford, England
 
B

Beetle

Put text boxes in the footer of your *subform* that
will total the values you want using a Control Source
like =Sum([SomeField]). Make them hidden if you
don't want the users to see them there.

Then put text boxes in your main form which will
refer to the text boxes in your subforms footer. Use
a Control Source like;

=[SubformControl].Form![txtSubTotal]

Where SubformControl is the name of the window that
holds the subform and txtSubTotal is the name of the
text box in the subforms footer. Keep in mind that the name
of the SubformControl may not necessarily be the same as
the name of the subform itself.
 
J

Jack

Thank you Beetle,
It works perfect. It gives the the info I want for each record and when I
leave the field in the subform it updates the information. Now all I have to
do is have it update it when I leave a field, but I am sure I can do that If
I play with the leave field command. What does the " ! " do? I don't think I
have ever used it in any other programing language. I would never have
thought you could put calculations in a text box, but it seems a good thing
that you can.
--
Thank you, Jack


Beetle said:
Put text boxes in the footer of your *subform* that
will total the values you want using a Control Source
like =Sum([SomeField]). Make them hidden if you
don't want the users to see them there.

Then put text boxes in your main form which will
refer to the text boxes in your subforms footer. Use
a Control Source like;

=[SubformControl].Form![txtSubTotal]

Where SubformControl is the name of the window that
holds the subform and txtSubTotal is the name of the
text box in the subforms footer. Keep in mind that the name
of the SubformControl may not necessarily be the same as
the name of the subform itself.

--
_________

Sean Bailey


 

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