cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Crystal Reports - Issue With Shared Variables

Former Member
0 Likes
3,705

I am having an issue with shared variables that are going from my subreport to my main report. In my subreport I want to pass the sum of the formula ActualCFS and the count of field tbnatur.desc to my main report. I will focus on just one of these, as whatever the problem is with one seems to be the same problem with the other. In a nutshell, these formulas give me exactly what they should when they are on the subreport, so I feel they are working properly. The problem is that the value that is passed to the main report for both formulas are both exactly 554 short of what they each should be.

I have this formula in my subreport:

Shared NumberVar CountCFS;
CountCFS := CountCFS + Sum ({@ActualCFS});
CountCFS;

I have this formula in my main report:

Shared NumberVar CountCFS;
CountCFS

Again, when I place the formulas on the subreport they are correct. But the values on the main report are both short of what they should be by 554 and I absolutely cannot figure out why.

View Entire Topic
DellSC
Active Contributor
0 Likes

1. Are you initializing CountCFS to 0 in the main report before the first time the subreport is called? The best way to do this would be in the report header section with a formula that looks like this:

Shared NumberVar CountCFS := 0;
""

The empty string at the end ensures that it doesn't display anything.

2. What type of section are you displaying it in? Is it AFTER all of the subreports have run? The variable won't have a complete value until after they've all run.

3. Try constraining which pass the variable is calculated in by making "WhilePrintingRecords;" the first line in all of the formulas.

-Dell

Former Member
0 Likes

1. I have added this into the report header.

2. I do have the shared value after the subreport has ran. Again, it's passing a value, it's just 554 short of what it should be passing. I know the formula on the subreport end are good because all of the math is correct there. It just gets wonky on the main report.

3. Added WhilePrintingRecords;

Tried all of these suggestions and it is still displaying the incorrect value on the main report.

DellSC
Active Contributor
0 Likes

How many times does the subreport run and what type of section is the formula in on the subreport?

-Dell

Former Member
0 Likes

The subreport only runs once. It is located in Group Header #1 in the main report. The formula is on the Report Footer in the subreport.