Another nice new feature of Crystal Reports is the ability
to dynamically filter the report without writing any code. This is done with
parameter fields and the new Saved Data option for the Selection Formula.
Assuming you followed the steps above you should close your browser to stop
debugging. Follow these steps to learn how to add this new feature to the
Employee List report.
We'll change this report so the user can filter the report
by an employee's hire date.
1.
Right click on the Parameter Fields node in the Field Explorer and
select New… from the pop-up menu.
2.
Enter Hire Start Date for the Name.
3.
Change the Type to Date.
4.
Click the OK button.
5.
Right click on the Parameter Fields node again and select New… from the
pop-up menu.
6.
Enter Hire End Date for the Name.
7.
Change the Type to Date.
8.
Click the OK button.
9.
From the main menu select Crystal ReportsàReportàSelection FormulaàSaved Data….
10. Enter
the following formula:
if {Employee.HireDate} >={?Hire Start Date} and {Employee.HireDate} <= {?Hire End Date} then
true
else
false
11. Click
the Save and close button.
12. Run
the report again. This time when it runs the user will be prompted to enter
the Hire Start and End dates.
13. Enter
1/1/2000 for the Hire Start Date.
14. Enter
12/31/2000 for the Hire End Date.
15. Click
the OK button. You should only see records for employees hired in the year
2000.
16. On
the left hand side of the viewer you should see a question mark inside
parenthesis. (?). Click on this. This will display the parameters panel.
17. Change
the start date to 1/1/2001 and the end date to 12/31/2001.
18. Click
the Apply button. You should now see the employees hired in 2001.
This is a nice new way to display the parameters in a report
rather than have the user refresh or run the report again.