Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to include OnDemand Subreports in an exported file

Subreports

How to include OnDemand Subreports in an exported file

by  sayden  Posted    (Edited  )
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:
Code:
crSubreport = crReport.OpenSubreport(crSubreportObject.SubreportName)
crSubreport.EnableOnDemand = False

Use:
Code:
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
'false'.
Example Formula
---------------
Code:
'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
Next

'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.
Sayden
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top