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

Use running totals or formulas from Sub-Rpt in Main? 2

Status
Not open for further replies.

Hueby

MIS
Oct 20, 2004
321
0
0
US
Hi, quick question...

Can you take a running total, or formula, from a Sub-Report to use for calculations in your "main" report?

I have a total in a sub report that I want to add with totals from the main report. Any ideas?
 
In the subreport, you need to create a formula that allows you to share the value:

whileprintingrecords;
shared numbervar subrpttot := sum({table.amt});

You must place this formula somewhere on the subreport canvas.

Then in the main report, create a formula which references the shared variable and does the calculation, e.g., the following would provide a grand total of values from asubreport placed in a group section:

//{@accum} to be placed in the section below the one in which the
//subreport is located (insert if necessary):

whileprintingrecords;
shared numbervar subrpttot;
numbervar grtot;

grtot := grtot + subrpttot;

Then in the report footer, add this formula:

whileprintingrecords;
numbervar grtot;

Or in these formulas you could do calculations as in:

whileprintingrecords;
shared numbervar subrpttot;

subrpttot + sum({table.amt},{table.group})

etc.

-LB
 
Okay,

in my main report I have the formula

whileprintingrecords;
shared numbervar mat;
shared numbervar hcost;
numbervar total;

total := mat + hcost + {SumEqOtherALL;1.EqTotal};

...and it gives me a error "A number is required here" ...and it is because of the {.EqTotal} value I want to add along with the other two values from the sub-reports.

What can I do about this??? Thanks
 
The likely problem is that CR doesn't see {SumEqOtherALL;1.EqTotal} as a Number date type. Try using the CDbl or ToNumber function to cast it to a Number:

total := mat + hcost + CDbl({SumEqOtherALL;1.EqTotal});

-dave
 
I'm guessing that {SumEqOtherALL;1.EqTotal} must be a string, so change your formula to:

whileprintingrecords;
shared numbervar mat;
shared numbervar hcost;
numbervar total;

total := mat + hcost + val({SumEqOtherALL;1.EqTotal});

-LB
 
Ahhhh okay!

using "CDbl({SumEqOtherALL;1.EqTotal})" did the trick. Thank you!
 
Alright, from the directions above... I have the formulas in my subreports and they are providing the correct values needed.

(an example of one is:
whileprintingrecords;
shared numbervar hcost := sum({HourCost;1.hourcost});)

Now in my main form, I have my formula to do the calculations like so..

whileprintingrecords;
shared numbervar mat;
shared numbervar hcost;
numbervar total;

total := mat + hcost + CDbl({SumEqOtherALL;1.EqTotal});

... I want this ran for each change of group. So i have the formula below in my group footer:

whileprintingrecords;
numbervar total;

Putting these last two formulas in the group footer doesn't work right. The first group is just the ({SumEqOtherALL;1.EqTotal}) value, and the second group is a number i have no clue from.

If i put these formulas in the Report Footer, then the LAST group calculates fine, but the first one doesn't at all.

Obviously, I'm not putting the correct formula in the right spot, or not doing something right here..... any clues?

Simply put, this is what i'm trying to do. I have my Main Report, 2 sub-reports and I will have several groups. I am calculating a total for EACH group from the 2 values pulled from the sub-reports and one value from the main report.
 
You need to describe your report structure--your groups, the exact locations of the subreports, and the location of the formulas where you are doing calculations using shared variables from the subreports. We should probably also know how you are linking the subreports to the main report.

If you are wanting group subtotals, you need to add a reset formula in the main report group header of the group for which you want the subtotal, as in:

whileprintingrecords;
shared numbervar mat := 0;
shared numbervar hcost := 0;
numbervar total := 0;

Please note that shared variables are only available in report sections below the one in which the subreport is located, so you may have to insert sections to accomplish this.

-LB
 
Has anyone seen this problem? I have a subreport where I am getting a running total for a subtotal of time by a main number for time worked. Then I have formula below that is getting adding all the subtotals together.
WhilePrintingRecords;
Shared NumberVar GrandTotal1;
GrandTotal1:=GrandTotal1+{#RTTime}

In my primary report I have the following.

Shared NumberVar GrandTotal1;
GrandTotal1
The above works fine but when I export it to Excel, it doubles the Grand Total so that if the total is 150 in my report, it becomes 300 on the export. All the other data shows up correctly. Has anyone seen this and is there an answer for it. I'm running Crystal ver 8.5 and Excel XP.

I hope someone else has seen this and there is a logical explanation for the problem.

Desperate!
 
Please note that shared variables are only available in report sections below the one in which the subreport is located, so you may have to insert sections to accomplish this."

That was my exact problem. I added another footer section, ALONG with a reset formula to my group, and bingo - works great now.

THANK YOU!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top