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

Formulas and sub-reports

Status
Not open for further replies.

Saners

Programmer
Jan 14, 2004
27
GB
I have a problem calculating a formula using shared number variables and sub-reports. I have checked out FAQs and thread767-857392 but it still is not working properly.

I am running CR10 using a Stored Procedure in SQL 2005.

1. I define 3 shared variables in the detail section of my main report:

WhilePrintingRecords;
Shared NumberVar CurrFunding;
Shared NumberVar PrevFunding;
Shared NumberVar TotalPrevFunding;

2. I calculate shared NumberVar CurrFunding in the detail section of my main report:

WhilePrintingRecords;
Shared NumberVar CurrFunding := 0;
Shared NumberVar CurrFunding := {apsp_srptFundingChange;1.CorporateFunding1}+{apsp_srptFundingChange;1.CorporateFunding2}+{apsp_srptFundingChange;1.InternalFunding};

3. I calculate shared NumberVar PrevFunding in the detail section of subbreport1:

WhilePrintingRecords;
Shared NumberVar PrevFunding := 0;
Shared NumberVar PrevFunding := {apsp_srptFundingChangeSub;1.CorporateFunding1}+{apsp_srptFundingChangeSub;1.CorporateFunding2}+{apsp_srptFundingChangeSub;1.InternalFunding};

4. I place subreport1 in the detail section of my main report.

5. So shared NumberVar CurrFunding and PrevFunding are calculated for each detail line.

6. I calculate shared NumberVar TotalPrevFunding in the detail section of subreport2:

WhilePrintingRecords;
shared NumberVar TotalPrevFunding := Shared NumberVar TotalPrevFunding + (Shared NumberVar CurrFunding - Shared NumberVar PrevFunding);

7. I place subreport2 in the detail section of the main report

8. I display the value of shared NumberVar TotalPrevFunding in the report footer.

My problem is calculating TotalPrevFunding. When I first run the report the value is correct. When I re-run the report using the same parameters the value is out by 168.

For debugging purposes I have tried displaying TotalPrevFunding on each detail line to see how the field is being calculated. The field is calculated correctly until the final page when an extra value is added to it.

The report has one detail section.

Any help will be greatly appreciated as I have spent a considerable amount of time on this and feel I need fresh ideas.

Many thanks.

Saners.













 
Place subreport 2 in a detail_b section.

-LB
 
Thanks for the prompt reply. That fixed the calculation problem.

However adding a subreport2 puts the report rows out of alignment and this data will be downloaded into a spreadsheet. Is there any way I can create a formula in subreport1 to access the value calculated in subreport2. Using EvaluateAfter maybe and supress subreport2?

Thanks again.
 
Sorry should have said:

However moving subreport2 to a detail_b section puts the report rows out of alignment and this data will be downloaded into a spreadsheet. Is there any way I can create a formula in subreport1 in detail_a to access the value calculated in subreport2 in detail_b? Using EvaluateAfter maybe and supress subreport2?

 
Do you actually need to display the sub2 result in the detail section? Or only in the report footer? If you don't need to display it, then suppress all sections WITHIN the sub2, format sub2 (format subreport->subreport) to "suppress blank subreport", and format detail_b to "suppess blank section". Do NOT suppress the sub2 itself or the entire detail_b section.

-LB
 
Thank you. The report is now working perfectly. Really appreciate the quick replies.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top