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

Subtotalling from subreports

Status
Not open for further replies.

JamesFlowers

Programmer
Mar 23, 2001
97
GB
Hi, Im using CR vers 8 and I have 5 subreports on my main report like so

custa
order sr1 sr2 sr3 sr4 srtot
1 1 1 1 1 4
2 2 2 2 2 8

custb
order sr1 sr2 sr3 sr4 srtot
1 3 3 3 3 12
2 4 4 4 4 16



The four sr are passing via four shared variables there values to the srtot report.

I would like to pass the totals of the srtot to a subtotal shown here of 12 by customer a and 28 by customer b.

There are no other ways of getting the subtotals back.

Any help or suggestions are appreciated.

James Flowers
 
There may be a way to get those totals
via direct SQL rather than through the subreports,
but let's take your word for it and assume you
can't do that.

You can use shared variables to pass the values from
the subreports to the main report.

Cheers,
- Ido
ixm7@psu.edu
 
In the Main report simply create a formula that adds up the values sent back by the individual subreports.

eg:
WhilePrintingrecords
shared numbervar Subrpt1_total;
shared numbervar Subrpt2_total;
shared numbervar Subrpt3_total;
shared numbervar Subrpt4_total;

Subrpt1_total + Subrpt2_total + Subrpt3_total + Subrpt4_total

One trick I use to garuantee the subreports are evaluated first is to place them in a subsection immediately before you need them. The section must not be suppressed but can be made very thin...make certain all fields in each subreport are suppressed and remove borders so the subreports themselves are invisible...I usually color code subreports red conditionally in the main report so I can find them later ( if 1 = 1 then crNoColor else crRed [this will make them visible in design but not in the report itself])
 
IdoMillet, beleive me if there was any way I could have gotten these totals via SQL I would have done it, but they are procedures produced from the DB.

the shared variable route is the way I have been looking at it but if I do it the way you have suggested it only repeats the last line before where I want it grouped, ie it shows

custa
order sr1 sr2 sr3 sr4 srtot
1 1 1 1 1 4
2 2 2 2 2 8
8
custb
order sr1 sr2 sr3 sr4 srtot
1 3 3 3 3 12
2 4 4 4 4 16
16

not the totals for the srtot which should be 12 and 38.

regards James Flowers


 
If the
4
8
are two instances of the same subreport, you need to accumulate these values in another variable in the main report.

If they are a single instance, you nedd to accumulate
their values in the shared variable inside the subreport.

By accumulate I simply mean something like:
varname := varname + value

Cheers,
- Ido
ixm7@psu.edu
 
I am having a problem like this as well. However my problem is that I have my subreports grouped by each day, and I'm trying to pass a total or sum of a field from all the days that appear in the sub to the main.

I can't get this to work correctly because the way the sub and main reports are grouped. The only thing it will pass through is the total for each day. I've tried placing the subreport field in different places on the main report, but I just can't get it to work.

Any suggestions?

Darrick
darrick3@yahoo.com
 
Darrick,

Sounds like you are expecting the same shared variable to be passsed from the subreport to the main report several times. Subreports pass the value to the main report only once; when the subreport gets processed.

So get the variable in the subreport to accumulate the full value you are looking for and pass that to the main report.

If you need multiple values, break the subreport into multiple subreports.

Cheers,
- Ido ixm7@psu.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top