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

Shared variable returns zero from subreport

Status
Not open for further replies.

sdonaldson

Programmer
Jul 13, 2001
19
GB
I have a problem passing data from a subreport to the main report via a shared variable.
I am using CR 8.5.0.217 Developer Edition on Windows 2000.

Main report has following formulae:

Report Header:
--------------
{@Year1YTDActualRunningTotalReset}
WhilePrintingRecords;
Global CurrencyVar Year1YTDActualRunningTotal := 0;
Shared CurrencyVar SharedYear1YTDActual := 0;

Details :
------------
{@Year1YTDActualRunningTotalCalculate}
WhilePrintingRecords;
Shared CurrencyVar SharedYear1YTDActual;
Global CurrencyVar Year1YTDActualRunningTotal := Year1YTDActualRunningTotal + SharedYear1YTDActual;

Report Footer:
--------------
WhilePrintingRecords;
Global CurrencyVar Year1YTDActualRunningTotal;
Year1YTDActualRunningTotal


The Details [a] section of the main report contains a subreport as follows:

Details:
--------
{@Year1YTDActual} formula which adds one or more table fields together according to the value in a parameter which is passed into the subreport from the main report.
This formula is working OK.

Report Footer:
--------------
{@SetSharedVariables}
WhilePrintingRecords;
Shared CurrencyVar SharedYear1YTDActual := {@Year1YTDActual};
SharedYear1YTDActual


Problem is that the SharedYear1YTDActual variable is being populated by the subreport (it shows the correct value in the subreport Report Footer), but it is always zero in the main report.
The value assigned to SharedYear1YTDActual in the {@Year1YTDActualRunningTotalReset} formula in the main report Report Header is the only value that the {@Year1YTDActualRunningTotalCalculate} formula gets.

Am I missing something or is there a problem with shared variables in v8.5 ?

Thanks in advance,
Shaun
 
Cursory Examination: I have had problems with Global variables retaining values. Try changing to Shared and see if that is the problem.
 
Shared variables produce the same result, ie, zero (or whatever value I initialize the Year1YTDActualRunningTotal variable with in the {@Year1YTDActualRunningTotalReset} formula).
Any more ideas anyone...?

Shaun
 
Is the subreport run before you need the data???

since you require it in the details section it should be setup as follows:


Main report

detail a - the subreport placed here (make as thin as
possible and suppress all lines in the
subreport to make invisible
detail b - the formulas using shared data placed here

Use "Shared" for only variables transfering data...other variables can be declared "global" if you want but I prefer to redefine in each formula as simple "NumberVar" etc...

the reason is for long term maintenance...you don't have to go looking through formulas to see if a variable was mis defined

hopes this helps Jim
JimBroadbent@Hotmail.com
 
I've fixed it but I don't know how !?
I created the report again from scratch and now it works.
Thanks anyway...

Shaun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top