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.crReportDocu ment.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 CrystalDecision s.CrystalReport s.Engine
Imports CrystalDecision s.Shared
Imports System.Configur ation.Configura tionSettings
Public Class frmRptMPLCounty
Inherits System.Web.UI.P age
Public InternalOnly
Public CompFromDate
Public CompToDate
Public RptType
'CR Variables
Dim crParameterFiel ds As ParameterFields
Dim crParameterFiel d As ParameterField
Dim crParameterDisc reteValue As ParameterDiscre teValue
Dim crReportDocumen t As rptMasterPolicy ListingCounty
Dim crExportOptions As ExportOptions
Dim crDiskFileDesti nationOptions As DiskFileDestina tionOptions
Dim crSections As Sections
Dim crSection As Section
Dim crReportObjects As ReportObjects
Dim crReportObject As ReportObject
Dim crSubreportObje ct As SubreportObject
Dim subRepDoc As New ReportDocument
Dim Fname As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
'Populate report parameters
InternalOnly = Session("Intern alOnly")
CompFromDate = Session("CompFr omDate")
CompToDate = Session("CompTo Date")
RptType = Session("RptTyp e")
'Create an instance of the strongly-typed report object
crReportDocumen t = New rptMasterPolicy ListingCounty
'Set the Report's SQL Connection
Me.SetSQLConnec tion()
'Create a new instance of a discrete parameter object to set the
first value for the parameter.
crParameterDisc reteValue = New ParameterDiscre teValue
crParameterDisc reteValue.Value = InternalOnly
'Define the parameter field to pass the parameter values to.
crParameterFiel d = New ParameterField
crParameterFiel d.ParameterFiel dName = "InternalOn ly"
'Pass the first value to the discrete parameter
crParameterFiel d.CurrentValues .Add(crParamete rDiscreteValue)
'Create an instance of the parameter fields collection, and pass
the discrete parameter with the discrete value to the
'collection of parameter fields.
crParameterFiel ds = New ParameterFields
crParameterFiel ds.Add(crParame terField)
'Create a new instance of a discrete parameter object to set the
first value for the parameter.
crParameterDisc reteValue = New ParameterDiscre teValue
crParameterDisc reteValue.Value = CompFromDate
'Define the parameter field to pass the parameter values to.
crParameterFiel d = New ParameterField
crParameterFiel d.ParameterFiel dName = "CompFromDa te"
'Pass the first value to the discrete parameter
crParameterFiel d.CurrentValues .Add(crParamete rDiscreteValue)
crParameterFiel ds.Add(crParame terField)
'Create a new instance of a discrete parameter object to set the
first value for the parameter.
crParameterDisc reteValue = New ParameterDiscre teValue
crParameterDisc reteValue.Value = CompToDate
'Define the parameter field to pass the parameter values to.
crParameterFiel d = New ParameterField
crParameterFiel d.ParameterFiel dName = "CompToDate "
'Pass the first value to the discrete parameter
crParameterFiel d.CurrentValues .Add(crParamete rDiscreteValue)
crParameterFiel ds.Add(crParame terField)
'Create a new instance of a discrete parameter object to set the
first value for the parameter.
crParameterDisc reteValue = New ParameterDiscre teValue
crParameterDisc reteValue.Value = RptType
'Define the parameter field to pass the parameter values to.
crParameterFiel d = New ParameterField
crParameterFiel d.ParameterFiel dName = "RptType"
'Pass the first value to the discrete parameter
crParameterFiel d.CurrentValues .Add(crParamete rDiscreteValue)
crParameterFiel ds.Add(crParame terField)
'The collection of parameter fields must be set to the viewer
CrystalReportVi ewer1.Parameter FieldInfo = crParameterFiel ds
'Set the viewer to the report object to be previewed. This
'must be done after the parameter information has been set.
Me.CrystalRepor tViewer1.Report Source = crReportDocumen t
'Refresh the report to ensure that the report retreives current
db info
Me.CrystalRepor tViewer1.Refres hReport()
End Sub
Private Sub btnPrint_Click( ByVal sender As Object, ByVal e As
System.EventArg s) Handles btnPrint.Click
'Setup report parameter fields
Dim pFldDefs As ParameterFieldD efinitions
Dim pFldDef As ParameterFieldD efinition
Dim pValues As ParameterValues
Dim pDisValue As ParameterDiscre teValue
pFldDefs = crReportDocumen t.DataDefinitio n.ParameterFiel ds
'Set the Report parameter
pFldDef = pFldDefs.Item(" InternalOnly")
pValues = pFldDef.Current Values
pDisValue = New ParameterDiscre teValue
pDisValue.Value = Me.InternalOnly
pValues.Add(pDi sValue)
pFldDef.ApplyCu rrentValues(pVa lues)
pFldDef = pFldDefs.Item(" CompFromDate")
pValues = pFldDef.Current Values
pDisValue = New ParameterDiscre teValue
pDisValue.Value = Me.CompFromDate
pValues.Add(pDi sValue)
'Set the Report parameter
pFldDef = pFldDefs.Item(" CompToDate")
pValues = pFldDef.Current Values
pDisValue = New ParameterDiscre teValue
pDisValue.Value = Me.CompToDate
pValues.Add(pDi sValue)
pFldDef.ApplyCu rrentValues(pVa lues)
pFldDef = pFldDefs.Item(" RptType")
pValues = pFldDef.Current Values
pDisValue = New ParameterDiscre teValue
pDisValue.Value = Me.RptType
pValues.Add(pDi sValue)
pFldDef.ApplyCu rrentValues(pVa lues)
'Temporary file used for the export
Fname = AppSettings.Get ("rptTempFil e") &
Session.Session ID.ToString & ".doc"
Me.crDiskFileDe stinationOption s = New DiskFileDestina tionOptions
Me.crDiskFileDe stinationOption s.DiskFileName = Fname
Me.crExportOpti ons = Me.crReportDocu ment.ExportOpti ons
With Me.crExportOpti ons
.DestinationOpt ions = Me.crDiskFileDe stinationOption s
.ExportDestinat ionType = ExportDestinati onType.DiskFile
.ExportFormatTy pe = ExportFormatTyp e.WordForWindow s
End With
Me.crReportDocu ment.Export()
Response.ClearC ontent()
Response.ClearH eaders()
Response.Conten tType = "applicatio n/msword"
Response.WriteF ile(Fname)
Response.Flush( )
Response.Close( )
'Delete the temp file
System.IO.File. Delete(Fname)
End Sub
Sub SetSQLConnectio n()
Dim crConnectionInf o As New ConnectionInfo
'Set the ConnectionInfo properties for logging on to the
Database
With crConnectionInf o
.ServerName = AppSettings.Get ("rptServerName ") ' <add
key="rptServerN ame" value="C:\Polic yTracking\Polic yTracking.mdb" />
End With
End Sub
Private Sub btnClose_Click( ByVal sender As Object, ByVal e As
System.EventArg s) Handles btnClose.Click
Response.Redire ct("frmRptMenu. aspx")
End Sub
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!