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

sum values in Main & sub reports 3

Status
Not open for further replies.

ajdesigns

Technical User
Jan 26, 2001
154
GB
I have a main report producing a sales invoice, I have added a sub report in order to bring in certain lines.Is there a way I can add the line totals from the sub to the main in order to get a grand total.
 
The general method is to use a shared variable. This example is for a date or a currency amount, but you should be able to adapt it for a count (NumVar):

Make a formula field in the subreport like
Shared dateVar
V_Today := {LoadStatus.LastDLoad}.
or
whileprintingrecords;
shared currencyvar WasSaved;
WasSaved:={#TotSaved};
WasSaved

To access it in the main report, create another formula field with
Shared dateVar
V_Today := V_Today.
or
whileprintingrecords;
shared currencyvar WasSaved;
WasSaved

But note limits - Shared variables can only be used for things that Crystal will process after the subreport has been processed. I wanted to use a subreport to find the date for data selection in the main report, but this was not allowed.

It helps to give your Crystal version, since newer versions have extra options, and some extra problems. I use Crystal 8.5.

[yinyang] Madawc Williams (East Anglia, UK) [yinyang]
 
Thanks Madawc
works great you saved me a lot of time.
 
I am also trying to show a total from a subreport on a main report. Your info is great, but I can't quite get it to work for me. I am extremely new to Crystal Reports and don't know all the ins and outs yet.

I have a main report that shows counts for new, mod and delete records grouped on customer. I also have a subreport that shows all records in the database for each customer, also grouped on customer. I have the totals for the main report in the report footer. I can't get the total for the subreport fields to show up correctly.

Ex

Customer1 New Mod Delete Total Records

Cust1 10 5 0 100
Cust2 7 3 2 200
Cust3 4 6 8 50

Totals: 21 14 10 0


The subreport is in the group footer section of the main report. I am guessing that I need to put the total for the "Total Records" in the main report. When I put it in the subreport the column looks like:

100
100
200
200
50
50

Any guidance would be greatly appreciated.

Thanks,
KellyTim
 
In the subreport, create a shared variable as follows:

//{@allrecords}:
whileprintingrecords;
shared numbervar allrecs := count({table.field});

Place this on your subreport canvas instead of the count summary.

Insert a second group footer section in the main report. Create a formula in the main report and place it in the group footer_b section (this section can be suppressed):

whileprintingrecords;
shared numbervar allrecs;
numbervar totrecs;

totrecs := totrecs + allrecs;

Then in the report footer add the following formula:

whileprintingrecords;
numbervar totrecs;

-LB
 
lbass,
Thanks so much for the help. Now that you showed me, it seems so clear. It works like a charm.

Thanks for letting me butt in to another user's line.

kellytim
 
Magic, I came across a similar problem, couldn't find a solution in Crystal Help, searched this forum, BINGO!. Solved in minutes.

Thanks to all who contributed (unknowingly) to solving my problem. [2thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top