Unable to export Crystal report containing subreports

H

Henry

I have written an ASP/VB.Net application via VS 2003 (Crystal V9) that
uses MS Access 2000 as its database. I can export reports that have no
linked sub reports for printing. However, I'm unable to export reports
that have linked subreports. I receive (a "Missing parameter field
current value") on the following statement:

Me.crReportDocument.Export()

The main report requires 4 parameters. The linked reports do not
require any parameters other than the linking field.


Any suggestions/help appreciated.


Complete Code Listing:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Configuration.ConfigurationSettings
Public Class frmRptMPLCounty
Inherits System.Web.UI.Page

Public InternalOnly
Public CompFromDate
Public CompToDate
Public RptType

'CR Variables
Dim crParameterFields As ParameterFields
Dim crParameterField As ParameterField
Dim crParameterDiscreteValue As ParameterDiscreteValue

Dim crReportDocument As rptMasterPolicyListingCounty
Dim crExportOptions As ExportOptions
Dim crDiskFileDestinationOptions As DiskFileDestinationOptions


Dim crSections As Sections
Dim crSection As Section
Dim crReportObjects As ReportObjects
Dim crReportObject As ReportObject
Dim crSubreportObject As SubreportObject
Dim subRepDoc As New ReportDocument

Dim Fname As String

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
'Populate report parameters
InternalOnly = Session("InternalOnly")
CompFromDate = Session("CompFromDate")
CompToDate = Session("CompToDate")
RptType = Session("RptType")


'Create an instance of the strongly-typed report object
crReportDocument = New rptMasterPolicyListingCounty

'Set the Report's SQL Connection
Me.SetSQLConnection()

'Create a new instance of a discrete parameter object to set the
first value for the parameter.
crParameterDiscreteValue = New ParameterDiscreteValue
crParameterDiscreteValue.Value = InternalOnly

'Define the parameter field to pass the parameter values to.
crParameterField = New ParameterField
crParameterField.ParameterFieldName = "InternalOnly"
'Pass the first value to the discrete parameter
crParameterField.CurrentValues.Add(crParameterDiscreteValue)

'Create an instance of the parameter fields collection, and pass
the discrete parameter with the discrete value to the
'collection of parameter fields.
crParameterFields = New ParameterFields
crParameterFields.Add(crParameterField)


'Create a new instance of a discrete parameter object to set the
first value for the parameter.
crParameterDiscreteValue = New ParameterDiscreteValue
crParameterDiscreteValue.Value = CompFromDate

'Define the parameter field to pass the parameter values to.
crParameterField = New ParameterField
crParameterField.ParameterFieldName = "CompFromDate"
'Pass the first value to the discrete parameter
crParameterField.CurrentValues.Add(crParameterDiscreteValue)

crParameterFields.Add(crParameterField)

'Create a new instance of a discrete parameter object to set the
first value for the parameter.
crParameterDiscreteValue = New ParameterDiscreteValue
crParameterDiscreteValue.Value = CompToDate

'Define the parameter field to pass the parameter values to.
crParameterField = New ParameterField
crParameterField.ParameterFieldName = "CompToDate"
'Pass the first value to the discrete parameter
crParameterField.CurrentValues.Add(crParameterDiscreteValue)

crParameterFields.Add(crParameterField)


'Create a new instance of a discrete parameter object to set the
first value for the parameter.
crParameterDiscreteValue = New ParameterDiscreteValue
crParameterDiscreteValue.Value = RptType

'Define the parameter field to pass the parameter values to.
crParameterField = New ParameterField
crParameterField.ParameterFieldName = "RptType"
'Pass the first value to the discrete parameter
crParameterField.CurrentValues.Add(crParameterDiscreteValue)

crParameterFields.Add(crParameterField)


'The collection of parameter fields must be set to the viewer
CrystalReportViewer1.ParameterFieldInfo = crParameterFields

'Set the viewer to the report object to be previewed. This
'must be done after the parameter information has been set.
Me.CrystalReportViewer1.ReportSource = crReportDocument

'Refresh the report to ensure that the report retreives current
db info
Me.CrystalReportViewer1.RefreshReport()
End Sub

Private Sub btnPrint_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnPrint.Click
'Setup report parameter fields
Dim pFldDefs As ParameterFieldDefinitions
Dim pFldDef As ParameterFieldDefinition
Dim pValues As ParameterValues
Dim pDisValue As ParameterDiscreteValue
pFldDefs = crReportDocument.DataDefinition.ParameterFields

'Set the Report parameter
pFldDef = pFldDefs.Item("InternalOnly")
pValues = pFldDef.CurrentValues
pDisValue = New ParameterDiscreteValue
pDisValue.Value = Me.InternalOnly
pValues.Add(pDisValue)
pFldDef.ApplyCurrentValues(pValues)

pFldDef = pFldDefs.Item("CompFromDate")
pValues = pFldDef.CurrentValues
pDisValue = New ParameterDiscreteValue
pDisValue.Value = Me.CompFromDate
pValues.Add(pDisValue)

'Set the Report parameter
pFldDef = pFldDefs.Item("CompToDate")
pValues = pFldDef.CurrentValues
pDisValue = New ParameterDiscreteValue
pDisValue.Value = Me.CompToDate
pValues.Add(pDisValue)
pFldDef.ApplyCurrentValues(pValues)

pFldDef = pFldDefs.Item("RptType")
pValues = pFldDef.CurrentValues
pDisValue = New ParameterDiscreteValue
pDisValue.Value = Me.RptType
pValues.Add(pDisValue)
pFldDef.ApplyCurrentValues(pValues)

'Temporary file used for the export
Fname = AppSettings.Get("rptTempFile") &
Session.SessionID.ToString & ".doc"

Me.crDiskFileDestinationOptions = New DiskFileDestinationOptions

Me.crDiskFileDestinationOptions.DiskFileName = Fname

Me.crExportOptions = Me.crReportDocument.ExportOptions

With Me.crExportOptions
.DestinationOptions = Me.crDiskFileDestinationOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.WordForWindows
End With

Me.crReportDocument.Export()

Response.ClearContent()

Response.ClearHeaders()

Response.ContentType = "application/msword"

Response.WriteFile(Fname)

Response.Flush()

Response.Close()

'Delete the temp file
System.IO.File.Delete(Fname)
End Sub

Sub SetSQLConnection()

Dim crConnectionInfo As New ConnectionInfo
'Set the ConnectionInfo properties for logging on to the
Database

With crConnectionInfo
.ServerName = AppSettings.Get("rptServerName") ' <add
key="rptServerName" value="C:\PolicyTracking\PolicyTracking.mdb" />
End With

End Sub

Private Sub btnClose_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnClose.Click
Response.Redirect("frmRptMenu.aspx")
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top