Skip to Content
0
Former Member
Mar 20, 2009 at 06:51 PM

Get blank report in Crystal Report Viewer when exporting to PDF

299 Views

I have an application that creates reports in the CrystalReportViewer while at the same time exports a PDF of that report. I am having a problem in which

performing the export causes the report in the ReportViewer and the PDF report to be blank. They have the header and column labels but no data. If I

comment out the Me.Export(reportExportOptions) line at the end of the exportPDFReport method the report in the ReportViewer works fine, displaying

data on the report.

I have other forms that perfrom this same type of function on different reports and work fine. In fact they use the same exportPDFReport method. This leads

me to believe that a difference in the reports may be causing the problem. But I can't figure out why.

I am using .net 3.5 with Crystal Reports 2008 (CR2008) full edition in Visual Studio 2008. Although the reports that work were probably created using

VS 2005 and the VS 2005 edition of Crystal, and which have since been updated to CR2008.

Has anyone else experienced this problem? If so, how did you resolve it?

Thanks for any help!

Code is below

Public Class frmAgedReceivables

  Inherits CustomWinControls.CustomForm
  Implements ICustomForm
  
... other properties and methods

Public Sub CreateAgedPremiumsReport()

    Dim billingType As String = "Direct"
    Dim reportType As String = String.Empty
    Dim frmDateProcess As New frmEnterProcessMonth()
    frmDateProcess.pikMonthYear.Value = TurmsController.CodeEffectiveDate
    frmDateProcess.lblMessage.Text = "Enter Processing Date"
    If frmDateProcess.ShowDialog(Me) = Windows.Forms.DialogResult.Cancel Then
      Return
    End If

    Me.InForceStripStatusLabel1.Text = "Creating Report"
    Me.Refresh()
    Dim report As New AgedReceivablesReport()
    report.Load(report.ReportPathAndName)
    Me.Refresh()

    Dim reportParmsArrayList As ArrayList = New ArrayList()
    reportParmsArrayList.Add(report.ParameterFields.Item(0).Name)
    reportParmsArrayList.Add(frmDateProcess.pikMonthYear.Value)
    reportParmsArrayList.Add(report.ParameterFields.Item(1).Name)

    If AgencyBillRadioButton.Checked Then
      billingType = "Agency"
    End If
    reportParmsArrayList.Add(billingType)
    reportParmsArrayList.Add(report.ParameterFields.Item(2).Name)
    reportParmsArrayList.Add(TurmsController.CurrentUser.UserName.Value)

    reportParmsArrayList.Add(report.ParameterFields.Item(3).Name)
    If NAICCheckBox.Checked Then
      reportType = "NAIC"
    End If

    reportParmsArrayList.Add(reportType)

    Dim parms As String() = {frmDateProcess.pikMonthYear.Value, billingType, reportType}
    Me.InForceStripStatusLabel1.Text = "Loading Data"
    Me.Refresh()
    report.getData(parms)

    Dim reportParms() = reportParmsArrayList.ToArray
    report.loadParameters(reportParms)

    report.ExportFileName = Microsoft.VisualBasic.Format(frmDateProcess.pikMonthYear.Value, "yyyyMM") + report.GetType.Name
    report.ExportFormat = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat
    report.exportPDFReport()

    Me.CrystalReportViewer1.ReportSource = report

  End Sub
End Class   
  
Public MustInherit Class TurmsReport
  Inherits CrystalDecisions.CrystalReports.Engine.ReportDocument
Implements _ITurmsReport
  
... other properties and methods
  
    Public Sub exportPDFReport() Implements _ITurmsReport.exportPDFReport
  
      Dim reportExportOptions As New ExportOptions
      Dim reportDiskFileDestinationOptions As New DiskFileDestinationOptions
      Dim reportFormatTypeOptions As New PdfRtfWordFormatOptions
  
      reportDiskFileDestinationOptions.DiskFileName = getExportPathAndName(ExportType.PDF)
  
      If Me.UsePageRange _
      AndAlso Me.FirstPageNumber > 0 _
      AndAlso Me.LastPageNumber > 0 Then
        reportFormatTypeOptions.UsePageRange = True
        reportFormatTypeOptions.FirstPageNumber = Me.FirstPageNumber
        reportFormatTypeOptions.LastPageNumber = Me.LastPageNumber
      End If
  
  
      With reportExportOptions
        .ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile
        .ExportFormatType = ExportFormatType.PortableDocFormat
        .ExportDestinationOptions = reportDiskFileDestinationOptions
        .ExportFormatOptions = reportFormatTypeOptions
      End With
  
      If Not System.IO.Directory.Exists(Me.ExportFilePath) Then
        System.IO.Directory.CreateDirectory(Me.ExportFilePath)
      End If
  
      Me.Export(reportExportOptions)
  
  End Sub
  
End Class