Crystal Reports XI (11): Error Number: 20525(502D) Unable to load report.
Problem solved with Crystal Reports XI being called from VBA (such as iFIX):
The Problem:
When trying to execute the Report.PrintOut function to print a Crystal Reports XI report (.rpt file), the user sees an error dialog “Error Number: 20525(502D) Unable to Load Report”. Also, if the user attempts to add the Crystal Reports XI Viewer as an object to an iFIX graphic, the iFIX Workspace will hang indefinitely with an hour-glass icon until the process is stopped with Task Manager.
The Cause:
iFIX 3.5 does not support Crystal Reports XI objects directly, since these objects do not support VBA.
The Solution:
Wrap the Crystal Reports XI objects in a .NET 1.1 program and call using the iFIX Shell command.
The entire VB.NET code (Visual Studio 2003) that wraps the print function is shown below. The call to the PrintTheReport sub passes in the report name/path which is retrieved from the command-line parameter.
Imports System.IO
Imports CrystalDecisions.CrystalReports.Engine
Public Class Form1
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
PrintTheReport(GetCommandLineArgs(0))
End
End Sub
Function GetCommandLineArgs() As String()
' Declare variables.
Dim separators As String = " "
Dim commands As String = Microsoft.VisualBasic.Command()
Dim args() As String = commands.Split(separators.ToCharArray)
Return args
End Function
Private Sub PrintTheReport(ByVal reportPath As String)
Try
'create a new ReportDocument object
Dim rdOrders As New ReportDocument
rdOrders.Load(reportPath)
'Use this to direct printout to a printer other than the default
'rdOrders.PrintOptions.PrinterName = "Adobe PDF"
rdOrders.PrintToPrinter(1, False, 0, 0)
Catch ex As Exception
MessageBox.Show(ex.Message, "Report could not be created", MessageBoxButtons.OK)
End Try
End Sub
End Class
This entire project must be installed by generating a .NET msi installer project in the solution. The msi installer installs the necessary Crystal Report XI dll files as well as this small wrapper program. The CR references for the project are shown below:
CrystalDecisions.CrystalReports.Engine
CrystalDecisions.Enterprise.Framework
CrystalDecisions.Enterprise.InfoStore
CrystalDecisions.ReportSource
CrystalDecisions.Windows.Forms
Printing the report from iFIX:
From within iFIX, the VBA Shell command is used to print the report (to the default printer), passing in the report path as a command-line parameter as shown. This can be scheduled as a background event, since the operator is not prompted at all. A report would simply pop out of the default printer on a periodic basis.
Private Sub CommandButton4_Click()
Dim retVal
retVal = Shell("C:\Dynamics\Reports\CrystalReportsFromiFIX.exe C:\Dynamics\Reports\HourlyReport.rpt", 0)
End Sub
David Heater, P.E.
RoviSys