Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

12.13 On-Demand Subreports

Using On-Demand Subreports

By default, subreports are run at the same time as the main report. When you view or print the main report, the subreport information is printed as well. This may result in a performance decrease because the subreport could require just as much time, if not more, to process as the main report. If performance becomes a problem, declare the subreport so that it isn’t bound to the main report. This is called an on-demand subreport.

An on-demand subreport doesn’t print at the same time as the main report. Instead, a hyperlink that describes the subreport is shown where the subreport should appear. When the user clicks on the hyperlink the subreport is processed and shown to the user. The on-demand subreport is shown on a separate tab in the viewer.

On-demand subreports are for reports viewed with the CrystalReportViewer control. If you send the report directly to the printer, only the placeholders are printed and not the subreport. This doesn’t give the reader the detail information they are looking for.

To define a subreport as being an on-demand subreport, use the Subreport tab of the Insert Subreport dialog box. At the bottom of the dialog box is an On-Demand Subreport checkbox. It is unchecked by default. Click on it to make the subreport an on-demand subreport.

By default, an on-demand subreport is shown as a hyperlink on the main report. The text is the name of the subreport.



Figure 12-10. On-demand subreports shown as a hyperlink.

When you click on the hyperlink the subreport is processed and displayed on a new tab in the viewer. Each on-demand subreport is displayed on its own tab.


Figure 12-11. On-demand subreports shown on a separate tab.

If you feel that displaying a hyperlink isn’t professional enough, you can display a customized placeholder instead. When you are in design mode, right-click on the subreport object and choose Format. Then go to the Subreport tab that is shown in Figure 12-12.



Figure 12-12. Formatting the subreport placeholder.

There is a formula button for modifying the caption that is displayed on the main report. You can enter a simple string in this formula or customize the string by concatenating data fields into it. The rest of the tabs on this dialog box can be used to format how the placeholder looks. For example, you can change the font, the background color and the border. Figure 12-13 shows the placeholder formatted with a border and a larger font size.



Figure 12-13. The subreport placeholder.