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

Shared variable from subreport

Status
Not open for further replies.

mcquam

Technical User
Feb 26, 2007
89
GB
Question
I'm trying to calculate an average cost per report for each person in my main report from 2 subreports; one with total costs per person and the other counting the number of reports per person. Each report can have several costs and the only common field is name. I can calculate a cost but only using the last record from each subreport. How do I get it to use records from each group?

I'm using CR11 and MSaccess.

Explanation
I have declared shared variables as follows:

The costs variable (@sumcosts):
Code:
WhilePrintingRecords;
shared currencyVar sumcosts := sum({ROSdata.NetFee},{ROSusernames.FullName});

The reports variable (@countreps):
Code:
whileprintingrecords;
shared numbervar reportstot := {#Reptot};

Main report calculation (@costperreport):
Code:
shared currencyvar sumcosts;
shared numbervar reportstot;

sumcosts/reportstot

In each subreport I have tried used running totals and formulas (as you will see above) which are referenced to the variables above. They appear in the group footer and are both grouped under name {ROSusernames.fullname}.
 
Hi:
- (@costperreport) this should be used in a section under the subreport -

so say

GF1a - this has ur subreport
GF1b - u can access the values calculated by subreport here

 
Looks like I'm doing soemthing wrong. I've tried as you suggest as many ways as I can think of including starting again. I either get the last group total or zero. The frustrating thing is I can see the correctly calculated numbers in each subreport.

I have simplified the report to test by just having 1 main report and one sub report.

Main report
Grouped on name (ROSusernames.FullName) with a running total counting the reports carried out. The subreport is in Gf1a and the group is in GF1b. I'm using the same formulas.



Subreport
Grouped on name (ROSusernames.FullName) with a group summary summing the fees. All are GF1. The subreport is linked with the group name field which is just a full name.


Doing it this way I only get zeros returned for the subreport.

 
when u say "The subreport is in Gf1a and the group is in GF1b."

does GF1b contain the formula where the value is calculated ?

 
Yes. Here are the details of my new test report where I'm getting the same problem:

Main report
Subreport is inserted at GF1a and supressed. Reports subtotalled in a group by fullname at GF1b. Formula inserted at GF1b as follows:
Code:
WhilePrintingRecords;
Shared numberVar mainfee;
Shared currencyVar subfee;
if mainfee=0 then 0 else
subfee/mainfee

Sub report
Fees per day subtotalled in a group by fullname and located in GF1 along with formula:
Code:
WhilePrintingRecords;
Shared currencyVar subfee := {#RTotal0};

There is no connection between the data in the main and sub apart from fullname. The main report counts the number of reports sold and the subreport adds up the various invoiced costs of doing so. I'm wondering if this is the problem as the 2 are not directly related. Also there is a selection on both reports for 1st - 3oth May.
 
I should also say that the reason I have ifmainfee=0 is that it is 0. If I say either formala=0 then 9 I get 9.
 
I have now returned correct data by linking the report and subreport properly but my calculation @costreport above now returns incorrect values. eg.

511/128= 3.16
92/11 = 39.36
449/123 = 2.80

Any suggestions?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top