cancel
Showing results for 
Search instead for 
Did you mean: 

Passing Multiple Values From Subreport to Main Report

Former Member
0 Kudos

Here is my dilemma. I have a main report that I am using to calculate total appointments by week. I am using a built in running total to sum up the count. Inside the Group, I have a subreport that calculates total doctor hours by week. Both of these reports work fine. However, what I need to do is pass back all of the doctors hours totals by week (24 weeks) back to the main report so I can perform additional calculations. Once I have the data in the main report, I need to be able to divide Total Appointments / Total Hours for each week. From this, I need to be able to graph it on a bar chart. How can I accomplish this? I tried fooling around with arrays but I was unable to have any success. Is there another way to pass multiple values from a subreport to a main report? Thanks.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Use Shared Variables, I most times create them with a SV_Fieldname .

so, in the sub report it might say SV_Sum_DR_Hours

then you would use the exact same name in the Main report.

This makes it easy to find out where the data is coming from, because the SV_ tells you it is a shared variable.

If you end up with more than one sub report, then also add SV_SR1_Fieldname and SV_SR2_Fieldname, this

will make it easier to troubleshoot later. In general Shared variables work ok, sometime you will need to leave

a sub-report variable source visable, to actually get the data to the main report. When this happens, I just

make it very very tiny. Info on Shared Variables below

Shared variables use the same memory block to store the value of a variable throughout the main report and all of its subreports. Thus shared variables are even more general than global variables. To use a shared variable, declare it in a formula in the main report as in the following example:

Shared NumberVar x := 1000;

and declare it in a formula in the subreport as in the following example:

Shared NumberVar x;

In order to use shared variables, the variable must be declared and assigned a value before it can be passed between the main report and the subreport.

You should also add an evaluation time, Like WhileReadingRecords;

These are the report specific functions: BeforeReadingRecords, WhileReadingRecords, WhilePrintingRecords and EvaluateAfter. You can use these functions to guide Crystal Reports as to when your formula should be evaluated.

Should the formula be evaluated before retrieving the records from the database, while reading the records from the database but before the records have been grouped, sorted and summarized, or while printing the report, when the records are grouped, sorted and summarized? In general, Crystal Reports sets an appropriate evaluation time for your formula, based on how much information the formula needs. For example, if a formula uses a database field, then it cannot be evaluated before the records are read from the database. However, you sometimes need to force a later evaluation time than normal to get the desired effect. See Using Global variables for an example.

Normally, the returned value of a function is used further in a formula. However, evaluation time functions are called to change the internal behavior of Crystal Reports and their return value is not used. They can be called by just placing their name in a separate statement, optionally preceded by the keyword Call.

Former Member
0 Kudos

I have used shared variables in many of my reports. Are you telling me that I need to create a separate shared variables for each week total? I would have to create 24 shared variables to pass back to the main report. If that is not the case, how would I use one shared variable that calculates the total doctor hours for each group, and then passes that value back to the main report so it matches the appointments in the main report. Also, where does the subreport need to be placed inside the main report. The main report currently has one group that is set to group by week. Thanks.

Former Member
0 Kudos

I have spent the last few hours trying to get the arrays to work. The array for storing the appointments (main report) works fine. However, I cannot pass multiple values from my subreport back to the main report. The first value in the array keeps repeating for each group. Instead of showing all 8 values in the array, each group footer shows the same number (Array index 1). Below is the report layout and formulas. I am sure it is something simple, but trying to find documentation for Crystal Reports is non-existent.

Main Report

page header - contians subreport (doctor hours)

Group Header 1 - Groups Appointments By Month

Group Footer 1 - Contains Array to store Appointments in the main report (uses running total called ApptTotal) - WORKING

ApptTotalArray

WhilePrintingRecords;

Shared stringVar Array myApptArray;

Shared NumberVar ArrayApptSize;

ArrayApptSize := ArrayApptSize + 1;

ReDim Preserve myApptArray[ArrayApptSize];

myApptArray[ArrayApptSize] := totext({#ApptTotal});

Group Footer 1 - Also contains array (in main report) to retrieve values from subreport - NOT WORKING

ResourceHoursArray

WhilePrintingRecords;

Shared stringVar Array mySharedArray;

local NumberVar ArraySize := ArraySize + 1;

ReDim Preserve mySharedArray[ArraySize];

totext(mySharedArray[ArraySize]);

The subreport contains this formula to store the hours in the array and send it back to the main report - WORKING

MonthHoursArray

WhilePrintingRecords;

Shared stringVar Array mySharedArray;

Shared NumberVar ArraySize;

ArraySize := ArraySize + 1;

ReDim Preserve mySharedArray[ArraySize];

mySharedArray[ArraySize] := totext({@LocationAllHours});

If I manually create a formula to retrieve doctor hours for a single month, it works. However, when I try to use the above code to retrieve all values from the array, it won't work. Here is the code for a single month that resides in the main report:

WhilePrintingRecords;

Shared stringVar Array mySharedArray;

Shared NumberVar ArraySize;

toNumber(mySharedArray[1]);