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

Variable from sub-report to Main

Status
Not open for further replies.

dhdh

IS-IT--Management
Jul 21, 2003
2
US
I need assistance on how to create a shared variable in a subreport by group that can be used in the main report for each corresponding group. any ideas?
 
You simply declare and use the same shared variable in the subreport and in the main report.

The main issue is that to use the value from the subreport, the formula referencing the variable in the main report must be placed in a section BELOW the section where the subreport is.

Cheers,
- Ido

CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
An example would be to right click the group header and select insertt section below. Create a formula in GH1A with something like:

whileprintingrecords;
shared numbervar SubNum := 0;

Place the subreport in GH1B and create a formula within the subreport with something like:

whileprintingrecords;
shared numbervar SubNum := sum({table.value});

or whatever you need.

In the Details or the Group Footer you can now reference the value using something like
whileprintingrecords;
shared numbervar SubNum;
If Subnum <> 0 then
Table.value} / Subnum
else
0

You can run the subreport at any level, but if you're doing so by groups, reset the value before the subreport fires, and use it afterwards.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top