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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subtotaling a subreport

Status
Not open for further replies.

SeeBee

Technical User
Mar 18, 2002
31
US
The problem crops up when there are no records in the subreport that correlate to the main report for a given group. The Shared Variable seems to retain the previous groups value and adds that to the present group in the main report. How can I get the Shared Variable to set itself to '0 or null' when there are no records for that group in the subreport?
 
Create an initialization formula in the group's header to set the variable to 0 before each time the forumula is called to calculate the total.
 
A subreport will always execute once ...even if there are no records...you just have to handle the case with no records returned...this is handled as follows

in the report header of the subreport place an initialization formula

@initialization

shared numbervar subtotal := 0;


any record select formula should be in the following format

(isnull({table.somevalue}) or {table.somevalue} = something) and

if you are grouping data in the subreport then group on a formula like the following:

@group1

if not isnull({Table.something}) then
{Table.something}
else
"Null Data"; // or 0 if {Table.something} is numeric

this allows the grouping to be made on a constant in Null data

your calculation formula should be something like

@Calc
shared numbervar subtotal;

if not isnull({Table.value} then
subtotal := Subtotal + {Table.value} ;

finally I always display the result in the report footer even though this (as is all sections of the subreport normally in this situation) is normally suppressed. when debugging you can unsuppress the report footer to see what is going on from the main report

@display
shared numbervar subtotal;
subtotal;


That should work for you


Jim
JimBroadbent@Hotmail.com


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top