View Full Version : Sum in subform Continous View


Jerry Stoner
04-13-2002, 09:24 AM
Ive done this before with no problem but cant seem to get it to work this time.I've a subform in continous view with fields txtUnitCost and txtQtySold.In the footer txtSubTot =[txtUnitCost]*[txtQtySold] gives the total for each record.ie. Record 1 txtUnitCost is 500.00 and txtQtySold is 5 it returns 2500.00. Record 2 txtUnitCost = 100 and txtQtySold = 1 txtSubTot = 100.00.
What I need is the total for all records in the subform ie. 2600.00. Tried =Sum([txtUnitCost]*[txtQtySold]) and I get #Error.The idea of course is to get the total for all products ordered on an invoice to show in the main form but I cant seem to get a sum of all records in the subform to show. The Footer of the subform is not visible and I am refering to the subform correctly =([frmTransDet].Form![txtSubTot]).Any Help?

[This message has been edited by Jerry Stoner (edited 04-13-2002).]

Jerry Stoner
04-13-2002, 10:56 AM
OK I got it to work but am totally confused as to why it works. I removed txt from txtUnitCost and txtQtySold. So I am now refering to the SOURCE of the Text Boxes not their names.Can someone please explain why this works?? Seems contrary to how I thought calculated controls work.

Pat Hartman
04-13-2002, 06:47 PM
Access doesn't allow you to refer to the name of a control in an aggregate function, you need to refer to the bound field. You refer to the control name when you want to set property values and to the bound field name when you want to do something with the data. This is why it is important to use different names for the controls if you need to add VBA code behind the form. It allows Access to understand whether you are referring to the control or to the bound field.

If you use Me.BoundFieldName, you'll see the list of properties available for the BoundField. If you use Me.ControlFieldName, you'll see the list of properties available for the control.

Jerry Stoner
04-14-2002, 05:47 AM
Thank you Pat, that was as usual a crystal clear explanation.It's amazing how much Ive learned from you and the other "heavyweights" on this forum.