问题
I have a number of subreports in which I calculate totals. In the main report I need the sum of those totals.
I don't know how to get acces to the totals in the subreports.
回答1:
You need to look into using Shared Variables, which can be read and written to by both the parent report and its subreports.
Example :
In parent report, a formula to initialise things called 'InitTotal', containing the text :
Shared NumberVar MyTotal := 0;
Place this formula in the report header and suppress it. Add a formula to each subreport called 'AddTotal', containing the text :
Shared NumberVar MyTotal := MyTotal + {FieldToAddToTotal};
Add this formula to the subreport's report footer and suppress it.
Finally, in the report footer of the parent report, add another formula called 'DisplayTotal' containing just the text :
Shared NumberVar MyTotal;
回答2:
You may also want to consider using a SQL Expression field. It generates a sub-query of sorts in the 'main' query's SELECT clause. As a result, the sub-query must return a scalar value. You can also correlate the sub-query with the main query.
SQL Express fields can also be used in the record-selection formula and will be passed to the database for processing.
See Crystal Reports: Using SQL Expression Fields for more details.
来源:https://stackoverflow.com/questions/5745810/crystal-reports-how-to-pass-a-parameter-from-a-subreport-to-the-parent-report