1
votes

I have a Crystal Report with a sub-report located in the footer of a group.

This sub-report displays a count based on parameters passed into it.

I would like to use this value in other calculations, and so I attempted to create a shared number variable.

However, when I place the formula with the shared number variable in the main report -- next to the sub-report itself -- it appears to display the value of the previous record.

Screen-shot of main report

(business-specific information removed)

Red square is the sub-report, green square is the variable I'm attempting to print

Sub-report displays correct value, green formula displays the sub-report value of the previous record.

Screenshot

Screen-shot of sub-report

One formula, in the report footer:

Screenshot

Formula that sub-report displays

I believe this formula correctly sets the variable at the time the formula is displayed (this may be a key to the issue I'm having):

Shared numberVar tryit;
tryit :=0;

If IsNull(count({IDNumber})) then
(
0
)
else
(
tryit :=count({IDNumber});
count({IDNumber})
)

Formula that displays shared variable on main report

Shared NumberVar tryit;
tryit;

Attempt 1: Move variable to below sub-report (unsuccessful)

Craig suggested that I move the variable I want to display to a footer section below where the sub-report executes.

I tried this; however, I have no need for the sub-report to display, and when I suppress it, all the shared variables appear to become 0 due to the sub-report not executing.

Below: red box is sub-report, orange is shared variable. Works as long as sub-report is also displayed, but I have no need for sub-report and need the shared variable to do additional calculations on parent report.

red box is sub-report, orange is shared variable. Works as long as sub-report is also displayed

1

1 Answers

1
votes

Insert a section below the one that contains your subreport--it will be group footer 1b. Move formula that references the shared variable to this new section.

** edit **

You won't be able to suppress the subreport; doing so will prevent it from being generated. I would recommend shrinking its vertical height and then disabling its 'can grow' property. Generally speaking, you only need to have the subreport's ReportFooter section visible for the variable to be generated. Consider setting the formula's text to white.

Alternately, you might be able to use a SQL Expression instead of the subreport. Its SQL will be embedded in the SELECT clause of the 'main' report. The SQL Expression needs to return a scalar value.

As far as the processing model is concerned, read this: Crystal Reports: Report Processing Model. In essence, the report engine needs to generate the subreport before it can populate a Shared variable. Having the subreport and formula that references a Shared variable in the same section isn't reliable.