Skip to Content

If you have a report with one or more On-Demand Subreports, when a user clicks on one of the links, the subreport will run causing a hit to the database. While this is no problem for users with a connection to the database, it makes it impossible to distribute the .rpt file to those that do not have this connection. If you want to be able to distribute reports with an ‘on-demand’ subreport and have the subreport data cached then this blog post should help.

Another reason that you may wish to cache data in your on-demand subreports is that you need the data to reflect a specific point in time when scheduling or publishing a report.

And yet another reason that you may wish to cache data in your on-demand subreports is so that they can be viewed in the free Crystal Reports Viewer.

Untitled.jpg

I use the term “on-demand” although this method does not utilize the Crystal Reports’ feature, “On-Demand Subreports”. This is a workaround but the end users will not know the difference. The steps will be outlined below and a sample report has also been attached. To view the report, extract the contents and change the .txt file extension to .rpt.

Steps to create fake on-demand subreports:

1) on your main report create a new formula named “flag” with syntax of

whileprintingrecords;

shared numbervar flag := 1;

2) create a new Report Header in your main report and move this new section up so that it is Report Header A

3) drop the new flag formula onto Report Header A

4) right click on your existing On-Demand Subreport, choose Format Subreport and on the Common Tab ensure that Can Grow is not checked

5) with the Format Subreport dialogue still open, go to the Subreport tab and ensure that On-demand Subreport is not checked then click OK

6) now right-click on your subreport and choose Edit

7) insert a new Report Header in your subreport and then move this new section up so that it is Report Header A

8) create a text object to put in the new header section that you would like to be the ‘link’ text …or create a formula if this is context / value driven

9) right click on the new header section and choose Section Expert

10) click on the Suppress formula button and add the following syntax so that the new section is suppressed when the subreport is opened

whileprintingrecords;

shared numbervar flag <> 1

11) now preview the main report to the last page so that each of the subreports in the main report runs

NOTE: In the File menu of your report ensure that Save Data With Report is selected.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply