how to pass a date range to a subreport using a parameter in crystal reports


Displaying data from a subreport based on a date range can be a bit tricky. Many people choose to simply hardcode the date range within the subreport. This certainly will work just fine, but a more dynamic approach would be to create a parameter that passes the required date range to the subreport.

In my example I will be using the SAP extreme samples database, utilizing the Bill and Bill_Payment tables.

I created the following report based on the Bill table and will use the Bill_Payment table for my subreport.



1. Open your report you wish to add your
2. From the Field Explorer, right click on Parameter Fields and click New.


3. Make the following changes to your parameter:

Name: Date Range
Type: Date
Under Value Options, Allow range values: True



4. Click OK.
5. Create a sub report or insert an existing report one into your report (Do not link the sub report at this time).
6. Right click on your sub report and click Edit Subreport.



7. Create the following new formula named ‘datelink’.

date({Bill_Payment.Date})

Replace the {Bill_Payment.Date} field with your date/time field that you wish to filter your subreport data on.

8. Return to the design tab.
9. Right click on your subreport and click on ‘Change Subreport Links...’



10. From the Subreport Links windows, select your parameter from the list under Available Fields and place it into the ‘Field(s) to link to:’ list.
11. Under ‘Select data in subreport based on field’ ensure that the datalink formula that you created within your subreport is selected and click OK.



12. Right click on your sub report and click Edit Subreport.



13. Open up the Select Expert. From the toolbar, click on ‘Report’ > Select Export > Record..



14. Make the following changes to the select statement:

{@datelink} in {?Pm-?Date Range} to {?Pm-?Date Range}
15. Click OK and return to the design tab.
16. Press F5 to refresh your report, populating your date range parameter when prompted.
17. Your subreport data should not be filtering on the data range parameter from the main report.

Any questions, just ask below..


Other Crystal Reports Tips you may find useful
 
Arrow Turning off smart linking Arrow Using the picture function
Arrow Change an image in the crystal report at runtime Arrow Suppressing blank lines in embedded fields


About About Us

Whether it's a complete automated report system with SAP Crystal Reports and SAP Business Objects Enterprise, or reporting on a single data source.. We can make it happen.

Support Support

Swansea, Wales

General Mailbox. 07740 890361

Email: bkuipersuk@gmail.com

Connect Connect

Linked Linked RSS