View Full Version : Calculation from Subform


sned
08-14-2001, 01:44 PM
I have a subform which contains the price and quantity of items required. In the main from I have a field called total cost. I'd like the total cost field to calculate for all of the items in the subform.
(It's probably blindingly simple but there we go.)

Carol
08-14-2001, 05:06 PM
In your subform, create a text field (if you have not already done so) to calculate the quantity x unit price. Call this field ExtendedPrice. In the footer of your subform, create a text field and in the control source put =Sum([ExtendedPrice]). Name this field OrderSubtotal. You can choose to leave this field visible set to no.
I am assuming that your sub form is set to datasheet view.

In your main form create another text field and place the following in the control source:

=[SubformName].Form![OrderSubtotal]

Replace "SubformName" with the actual name of your subform.

[This message has been edited by Carol (edited 08-14-2001).]

[This message has been edited by Carol (edited 08-14-2001).]

Jonathan Kok
08-15-2001, 10:16 AM
I'm having a similar problem--trying to create calculated fields on a subform. My counts & sums all return #Error (and yes, they're located on the Form Footer). I'm doing a couple of things differently, though.
[list=1]
I'm using a Countinous Form view for my subform (allowed for easier & tighter organization, plus better control over colors, column headers, etc).
I'm performing the sums on calculated fields created in the underlying query, ie, linetotal: [qty]*[price]. The Count field is not based on a calculated field, though, and it also returns #Error
[/list=a]
I've tried using datasheet view instead, same problem. I've also tried performing the line calculations on the form instead of the underlying query, again, same #Error. I've checked it all out, there's no mistake in the Control Source, no circular references.

The pathetic thing is that I've done this a hundred times, but I can't seem to see the problem.

(edited for clarity)

[This message has been edited by Jonathan Kok (edited 08-15-2001).]

Carol
08-15-2001, 07:59 PM
Usually receiving the "Error" message means that you have a naming problem. When you are using fields for count and sums, make sure that you are referring to the correct field Name, and not the fields Controlsource.