Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Business Objects: Crystal Reports 4 Other topics FAQ


How to include OnDemand Subreports in an exported file by sayden
Posted: 22 Nov 06

Version: Crystal Reports for Visual Studio.Net 2003
Related to: Crystal Reports KBase Article c2012680

I have been looking on and off for a few months for the code that will allow ondemand subreports to be exported as regular reports with the main report instead of just the links without success, and it seemed enableondemand was readonly but today I finally cracked it. The code is exactly the same as the one found in the Crystal Reports Support site (KBase Article ID:c2012680) except for replacing and moving of  one line: the one which assigns the EnableOnDemand property.

Instead of:


crSubreport = crReport.OpenSubreport(crSubreportObject.SubreportName)
crSubreport.EnableOnDemand = False



crSubreportObject.EnableOnDemand = False  
crSubreport = crReport.OpenSubreport(crSubreportObject.SubreportName)

Here is the Crystal Reports code adjusted to reflect the change. This exported successfully to: .pdf, .xls, .doc and .rtf and printed as well.
This can be done programatically using Crystal
Reports for .NET. Loop though the report object,
locate any subreport objects, and then set the
subreport object's 'EnableOnDemand' property to
Example Formula


'import namespaces at the top of the code page
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Dim crReport As New CrystalReport1()
Dim crSubreportObject As SubreportObject
Dim crSubreport As New ReportDocument()
Dim crTableLogOnInfos As New TableLogOnInfos()
Dim crTableLogOnInfo As TableLogOnInfo
Dim crTables As Tables
Dim crTable As Table
Dim crReportObjects As ReportObjects
Dim crReportObject As ReportObject
Dim LoopReportObject As Integer
Dim TableCounter As Integer

'accessing the reportobjects collection
crReportObjects = crReport.ReportDefinition.ReportObjects

'loop through report objects collection
For LoopReportObject = 0 To crReportObjects.Count - 1
crReportObject = mcrReportObjects.Item(LoopReportObject)

'check to see is the current report object in the
'report object collection is a subreport object
If crReportObject.Kind = ReportObjectKind.SubreportObject then
'if the report object is a subreport object
'then set it to a report
crSubreportObject = crReportObject

'This is where you set the property to show the
'subreport on export
crSubreportObject.EnableOnDemand = False      
crSubreport = crReport.OpenSubreport(crSubreportObject.SubreportName)

'Crystal Reports Old Code
'crSubreport.EnableOnDemand = False
End If

'View the report
CrystalReportViewer1.ReportSource = crReport

When the application is run, with the
EnableOnDemand property set to false, all on-demand
subreports become regular subreports. They will now
appear in the exported file.
Hope this helps/works for you as it did for me.

Back to Business Objects: Crystal Reports 4 Other topics FAQ Index
Back to Business Objects: Crystal Reports 4 Other topics Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close