Carry Data between 2 sub reports

I have a report where I want to carry data from 1 sub report to a 2nd sub report
Thought I was there with the following formula

WhilePrintingRecords;
Shared NumberVar MyValue2;

Shared StringVar Array loc_names;
Shared NumberVar Array loc_totals;
Shared NumberVar loc_count;
Local NumberVar i;

if {WOEQLIST.LOCATION} in loc_names then
(
// If LOCATION is in the loc_names array, find which entry it's in
// and then output the corresponding entry from loc_totals
  for i := 1 to loc_count do
    if loc_names [ i ] = {WOEQLIST.LOCATION} then
      exit for;
  loc_totals [ i ]
)
else
// If LOCATION is not in the loc_names array, just output 0
  0

but it is not carrying all the figures forward as can be seen in the attached
Am sure it just requires a slight mod to the formula
Please help

Gordon
Carry-Forward-figures.pdf
Gordon HughesDirectorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mlmccCommented:
DId you declare the variables in the main report and both subreports?

IN the main report add a formula to the report header

WhilePrintingRecords;
Shared NumberVar MyValue2;

Shared StringVar Array loc_names;
Shared NumberVar Array loc_totals;
Shared NumberVar loc_count;

Open in new window


IN subreport1 (must be in a section before subreport 2)
Add your formula

In subreport2 add a formula
WhilePrintingRecords;
Shared NumberVar MyValue2;

Shared StringVar Array loc_names;
Shared NumberVar Array loc_totals;
Shared NumberVar loc_count;

//Code to use the shared information

Open in new window


mlmcc
0
Gordon HughesDirectorAuthor Commented:
Hi mimcc

James helped with this
In the 1st sub report there is:
WhilePrintingRecords;
Shared NumberVar MyValue2;

Shared StringVar Array loc_names;
Shared NumberVar Array loc_totals;
Shared NumberVar loc_count;
Local NumberVar i;

MyValue2 := Sum ({@NoDoneInPeriod}, {WOEQLIST.LOCATION});

if loc_count > 0 and {WOEQLIST.LOCATION} in loc_names then
(
// If LOCATION is in the loc_names array, find which entry it's in
// and then add the Sum to the corresponding entry in loc_totals
  for i := 1 to loc_count do
    if loc_names [ i ] = {WOEQLIST.LOCATION} then
      exit for;
  loc_totals [ i ] := loc_totals [ i ] + Sum ({@NoDoneInPeriod}, {WOEQLIST.LOCATION});
)
else
(
// If LOCATION is not in the loc_names array, increment the count,
// resize (Redim) the array to match (Preserve keeps the existing
// array contents), and put LOCATION and the Sum in the last entries
  loc_count := loc_count + 1;
  Redim Preserve loc_names [ loc_count ];
  Redim Preserve loc_totals [ loc_count ];
  loc_names [ loc_count ] := {WOEQLIST.LOCATION};
  loc_totals [ loc_count ] := Sum ({@NoDoneInPeriod}, {WOEQLIST.LOCATION});
);

In the second report can only see
WhilePrintingRecords;
Shared NumberVar MyValue2;

Shared StringVar Array loc_names;
Shared NumberVar Array loc_totals;
Shared NumberVar loc_count;
Local NumberVar i;

if {WOEQLIST.LOCATION} in loc_names then
(
// If LOCATION is in the loc_names array, find which entry it's in
// and then output the corresponding entry from loc_totals
  for i := 1 to loc_count do
    if loc_names [ i ] = {WOEQLIST.LOCATION} then
      exit for;
  loc_totals [ i ]
)
else
// If LOCATION is not in the loc_names array, just output 0
  0


Does this make sense or is something missing
Gordon
0
mlmccCommented:
You need to also declare the shared variables in the main report otherwise there is no way carry the value through the main report from the 1st to the second subreport.

Since the subreports cannot communicate with each other directly the main report is used to carry the information from one to the other.  If it has no where to save the information then it cannot be given to the 2nd subreport.

mlmcc
0
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Gordon HughesDirectorAuthor Commented:
Hi mimcc

I have addedthe 2 formulae
1 in the main report and 1 in the 2nd sub report
I still get the 0 values

Gordon
0
mlmccCommented:
Is the main report formula in the report header?

Are the 2 subreports working on the same database?

mlmcc
0
Gordon HughesDirectorAuthor Commented:
Hi mimcc

I put  the following in the main report
WhilePrintingRecords;
Shared NumberVar MyValue2;

Shared StringVar Array loc_names;
Shared NumberVar Array loc_totals;
Shared NumberVar loc_count;

And yes they all look at the same database

Gordon
0
mlmccCommented:
Can you upload the rpt file?

mlmcc
0
Gordon HughesDirectorAuthor Commented:
Hi mimcc

rpt file attached with data hopefully

Gordon
Weekly-KPI-Report-Version-2a.rpt
0
James0628Commented:
I believe it's because you have @DoneFigureSite in the report header in the PlannedWork subreport.  The formula is trying to save the total for each group in the array, but since the formula is in the report header, it's only evaluated once, at the beginning of the subreport.  So you only get the total for the first group in the subreport (Merston).

 @DoneFigureSite should be in the LOCATION group header or footer, so that it can save the total for each LOCATION in the subreport.  I don't think it matters if it's the group header or footer, but it has to be one or the other (and not both, or it will add the group total twice).

 As I recall, you originally had the formula in the group header or footer, and in the subreport report header, and I told you to remove it from the report header, so that the first group (LOCATION) total was not added twice.  It seems that you removed the wrong copy of the formula.  :-)


 FYI, I could not see the saved data in the report that you posted.  When I opened it, I was prompted for a db connection.  After cancelling that prompt several times, I got a blank report.  Which means that I wasn't able to test moving the formula to the group header or footer, but I'm pretty confident that that's the problem.

 James
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gordon HughesDirectorAuthor Commented:
Excellent responses and solutions as always
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.