Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

16.09 Modifying Subreport Parameters

Modifying Subreport Parameters

Modifying the parameters of a subreport is the same as modifying any report object within a subreport. The code from Chapter 15 that references and instantiates subreport objects works with parameters as well.

Using the code in Chapter 15 as a basis to modify subreport parameters works great. But it can only be used with the ReportDocument object. If you recall from the discussion about modifying the viewer object, it limits what you can do. You can’t reference the more sophisticated ReportDocument object with the viewer control. So how are you supposed to modify the parameters of a subreport if the viewer doesn’t give you access to the ReportDocument object?

The ParameterFields collection of the viewer object has an overloaded indexer. In addition to passing it the parameter name, you can also pass the name of a subreport. Passing the subreport name gives you access to all the parameters on a subreport. If you pass an empty string as the subreport name, the main report’s parameters are referenced.

As an example, Step 3 from Listing 16-3 has been modified to demonstrate getting a parameter from a subreport. The rest of the code in Listing 16-3 works as is and modifies the subreport parameter as expected.

'Step 3: Reference the ParameterField object
ParameterField = ParameterFields("ParameterName", "SubReportName")

Even though you really only need to use this trick when modifying parameters with the viewer control, you can also do it with the ParameterFieldDefinition collection of the ReportDocument object. This is a nice shortcut compared to looping through all the report objects in the main report looking for the subreport object.