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

How do I pass date parameters to sub reports and use them in the selection criteria?

Report Development

How do I pass date parameters to sub reports and use them in the selection criteria?

by  BFAGG  Posted    (Edited  )
he following was developed for Crystal version 7 as there was a problem in linking dates.

1. Introduction
This document describes the steps that will allow nested sub reports to share some or all of the selection parameters of the parent report.

This document shows reports that will share a date range as their parameters as this is a common link between reports.

The instructions assume that both the Primary and Sub reports have been completed and that the sub report has been inserted into the footer of the Primary report.
2. Instructions
2.1. Set up the Primary Report
In the primary report, create 2 parameter fields called startdate and
enddate. You do not have to show these fields in the report.

These parameters are then shown in the report fields list as ?startdate and ?enddate.

Then create 2 formulas called startdate and enddate. The startdate formula should only contain the report field value {?startdate} and the enddate formula should only contain the report field value {?enddate}.

These Formulas are then shown in the report fields list as @startdate and @enddate.

These formulas are required because you cannot create a subreport
link based on a parameter field.

You must then edit the selection criteria for the main report to include the data range. Go to the menu options Report|Edit Selection Formula|Record and enter/include the following record selection criteria:

{table.datefield} >= {@startdate} and {table.datefield} <= {@enddate}
2.2. Set up the Sub Report
Create the same 2 parameter fields and the same 2 formula
fields in the subreport. These do not have to be on the actual report.
2.3. Link the Reports
To link the reports go to the menu options Edit|Subreport Links.
Select the formula @startdate from the available fields. This will activate field link section at the bottom of the screen. Remove the tick from the checkbox to deactivate this area.

Repeat with the formula @enddate. Then select OK to close the window.

Now edit the sub report. The above procedure will have created two parameter fields in the sub report,
{?Pm-@startdate} and {?Pm-@enddate}. These parameters represent the range value passed from the main report.

You will now have to edit the record selection formula for the sub report.
Select Report|Edit Selection Formula|Record from the menu and change the record selection to
read:
{table.datefield} >= {?Pm-@startdate} and {table.datefield} <= {?Pm-@enddate}.

Now, when the report is refreshed, the user will enter in the start and end dates in the main report and these values will populate the record selection formula in the subreport.

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top