You can quite easily export / pass parameters to crystal reports and export to any format from VB. To export to PDF you will require Crystal 8.5. The following code is an example. It takes an XML stream and merges the data with a crystal report. Formula fields on the report are concidered unique XML nodes.
Parameters can also be passed using 'Report.ParameterFields'.
This code also constructs ADO recordsets at runtime and populates them from the XML data.
You will need to add a reference to Crystal Reports 8.5 ActiveX design and runtime library.
Hope this is usefull.
Chris Dukes
Dim objformula As CRAXDRT.FormulaFieldDefinition
Dim objtables As DatabaseTable
Dim objfield As DatabaseFieldDefinition
Dim objADORecords As ADODB.Recordset
Dim StrTablename As String
Dim objNodes As MSXML2.IXMLDOMNodeList
Dim objelement As MSXML2.IXMLDOMElement
Dim i, j As Integer
Dim strFileName As String
Dim strUniqueReference As String
Dim mobjParam As CRAXDRT.ParameterFieldDefinition
If mobjcrystal Is Nothing Then
Set mobjcrystal = New CRAXDRT.Application
End If
Set mobjReport = mobjcrystal.OpenReport(Me.ReportFileName)
' Loop round for all the formula in the
' report and get the text from the
' XML document based on the name of the
' Crystal formula field
For Each objformula In mobjReport.FormulaFields
' If the formula field already has text in it
' do not overright the current text as the
' report could be using the formula
If Len(Trim(objformula.Text)) = 0 Then
objformula.Text = objXMLData.GetTextElement( _
objformula.FormulaFieldName, CrystalFormat)
End If
Next objformula
If mobjReport.ParameterFields.Count <> 0 Then
Set mobjParam = mobjReport.ParameterFields.GetItemByName( _
PARAMETER_TYPE)
mobjParam.AddCurrentValue (iReportType)
End If
' now loop around the main report
' tables and add the
' data sources
For Each objtables In mobjReport.Database.Tables
StrTablename = Left(objtables.Name, Len(objtables.Name) - 4)
Set objADORecords = objXMLData.GetRecordSet(StrTablename)
If objADORecords Is Nothing Then
For Each objfield In objtables.Fields
Call objXMLData.GenerateRecordSetFromCrystal( _
objADORecords, StrTablename, objfield.DatabaseFieldName, _
objfield.ValueType)
Next objfield
End If
If objADORecords.State <> 1 Then
objADORecords.Open
End If
Set objNodes = objXMLData.GetNodeList(StrTablename)
For i = 0 To objNodes.length - 1
Set objelement = objNodes.Item(i)
objADORecords.AddNew
If objelement.childNodes.length = 1 Then
objADORecords.Fields( _
objelement.baseName).Value = FormatValue( _
objelement.Text, _
objADORecords.Fields(objelement.baseName).Type)
Else
For j = 0 To objelement.childNodes.length - 1
objADORecords.Fields(objelement.childNodes( _
j).baseName).Value = FormatValue( _
objelement.childNodes(j).Text, _
objADORecords.Fields(objelement.childNodes( _
j).baseName).Type)
Next j
End If
objADORecords.Update
Next i
objtables.SetDataSource objADORecords, 3
Next objtables
' Process the report
mobjReport.ReadRecords
Set mobjExport = mobjReport.ExportOptions
' Export the file to PDF format
mobjExport.PDFExportAllPages = True
mobjExport.DestinationType = crEDTDiskFile
mobjExport.DiskFileName = strFilePath & "\" & strFileName & ".pdf"
mobjExport.FormatType = crEFTPortableDocFormat
mobjReport.Export False