Linking to Subreport Parameters
If the subreport has parameter fields in it, when the user refreshes the report they are prompted to enter values for the subreport parameters. If you don’t want the user to be prompted to enter a parameter value, you can link a field from the main report to the subreport parameter. This automatically populates the subreport parameter field with a value from the main report without prompting the user.
To link a field from the main report to a subreport parameter, right-click on the subreport in design mode and select Change Subreport Links. This opens the Subreport Links dialog box previously shown in Figure 9-4. In the Available Fields list, double-click the field from the main report that holds the value you want to pass to the subreport parameter. This adds the field to the Fields To Link To list on the right.
When you move a field to the Fields To Link To list, Crystal Reports’ default behavior is to automatically create a matching parameter in the subreport which is passed the value from the main report. If you look in the bottom left hand corner of the dialog box you’ll see that there is a parameter name with a prefix of “?Pm-…” However, in this circumstance you don’t need Crystal Reports to create a new parameter for you because the subreport already has a parameter that you want to link the data to. Instead of letting Crystal Reports create a new parameter, click on the dropdown box and select the existing parameter from the list. This links the field on the main report to the existing subreport parameter.
If you don’t see the subreport parameter in the dropdown list, then there is a data type mismatch between the chosen field in the main report and the parameter. Cancel your changes and go back to make sure that both the main report field and the subreport parameter have the same data type. If not, create a formula in the main report which converts the field to the proper data type and use this formula to link to the subreport parameter.
After selecting the existing subreport parameter to link to, the option to the right, Select Data In Subreport Based On Field becomes disabled. This option is no longer necessary since you are passing the data to an existing parameter.
Save your changes and refresh the report data. The subreport will get its data from the main report and you will no longer be prompted to enter a parameter value.