Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to subtotal a field in a subform

Status
Not open for further replies.

reidgivens

Technical User
Mar 24, 2003
24
0
0
US
I am attempting to create a subtotal on a form, but I need the totals of two fields in two seperate subforms. The subforms are in datasheet view, so I need to total of those feilds, then to total them together.

Please help, I have no idea where to start. Reid Givens
Webdeveloper
 
To obtain a total of a single series of values in a subform in a control on a mainform, use ..

DSUM(ColumnName,SubformQuery,SubformLinkMaster=SubformLinkChild)

What this does is use a Domain which is the same as your subform and add up all the values in the particular column.

For the sum of two totals just add two together.

Enjoy,
Tony
 
what do i put for
--
SubformQuery,SubformLinkMaster=SubformLinkChild
--
I have the name of the subform for SubformQuery
the primarykey of the table i am basin my report off of
and the foreign key equivalent in the subform table for SubformLinkChild

What is wrong here, i am getting a #name? error
Reid Givens
Webdeveloper
 
Hi reidgivens,

SubformQuery needs to be the same as the Source Object property of the Subform control - a pointer to the data source itself, not the subform based on it.

It sounds like you've got the others right, but for the record ...

SubformLinkMaster needs to be the same as the Link Master Field property of the subform control.

SubformLinkChild needs to be the same as the Link Child Field property of the subform control.

In other words you want to use the same data source as the subform, but just sum the one column rather than presenting all the data again.

Enjoy,
Tony
 
I have one last problem, when I use this, if a particular field is empty, it returns an error. How do tell it if there is no feilds that match the query, just put 0?

Thanks for your help. Reid Givens
Webdeveloper
 
Hi Reid,

What sort of error? I can't quickly make one happen. Which field is empty? DSUM should return NULL if the domain (query) contains no records. That might give a problem if you're trying to do operations on it, that's all I can think of at the moment.

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top