Crystal Reports Technique: Passing Data from Subreport to Parent

Crystal Reports Technique: Passing Data from Subreport to Parent

On a couple of occasions, we’ve have needed to sum data or concatenate a string within a crystal reports subreport, and then pass the data back to the parent report for display.

The key to doing this is passing the data in a variable within a Formula Field that exists on both the crystal reports subreport; as well as the parent report.


How to pass the data

In the subreport, do all your necessary calculations in a Formula Field, which should be added into the Report Footer. Add the following code into the Formula Field:

Shared CurrencyVar grandTotal := {@calculatedSum};

grandTotal;

The Shared qualifier allows you to pass the data through a declared variable. We declared the variable as a CurrencyVar, but you will need to declare your variable with the appropriate type. Other types are StringVar or NumberVar.

You can set the variable to a summed value or another Formula Field.

Now in the parent, add a Formula Field with the same name. Add similar code to access the variable and make sure the variable name is the same!

Shared CurrencyVar grandTotal;

grandTotal;

Now drag the Formula Field onto your report.

Suggested reading

Leave a Comment

Your email address will not be published. Required fields are marked *