'===================================================================================
'Create the Crystal Reports Objects
'===================================================================================
If Not IsObject(oApp) Then
Set oApp = CreateObject("CrystalRuntime.Application")
End If
' CREATE THE REPORT OBJECT
'
'The Report object is created by calling the Application object's OpenReport method.
Dim Path
Dim reportname
Path = "**YOUR PATH**"
reportname = "**YOUR REPORT.rpt**"
'OPEN THE REPORT (but destroy any previous one first)
If IsObject(oRpt) Then
Set oRpt = Nothing
End If
Set oRpt = oApp.OpenReport(Path & reportname, 1)
oRpt.MorePrintEngineErrorMessages = False
oRpt.EnableParameterPrompting = False
'Now we must tell the report to report off of the data in the recordset:
oRpt.DiscardSavedData
'Pass parameters to the report
'set up begin and end date to be the first and last days of the previous week
oRpt.ParameterFields(1).AddCurrentValue ***YOUR PARM***
Dim dbTable
' login to each of the report's tables
For Each dbTable In oRpt.Database.Tables
dbTable.SetLogOnInfo "**SERVER Connection**", "***DATABASE***", "**USER**", "**PASSWORD***"
Next
oRpt.ReadRecords
'====================================================================================
' Exporting the Crystal Report
'====================================================================================
outputPath = "**OUTPUT FILE PATH**"
outputfilename = "**OUTPUT FILE**"
Set fso = CreateObject("Scripting.FileSystemObject")
'delete final backup target file if it exists
If fso.FileExists(outputfilename & outputPath) Then
fso.DeleteFile outputfilename & outputPath
End If
ExportType = 31
'These lines collect the values passed from the calling HTML page for the export
'type and filename
'ExportOptions = oRpt.ExportOptions
'First we create an export options collection which allows us access
'to the exporting properties of the automation server.
oRpt.ExportOptions.DiskFileName = outputPath + CStr(outputfilename)
oRpt.ExportOptions.FormatType = CInt(ExportType)
'This line sets the file type that the report will be exported to. We
'use the value that we collected from the calling HTML page.
oRpt.ExportOptions.DestinationType = 1
'This line sets the destination of the exported file. 1 means that
'we are writing the file to disk.
On Error Resume Next
oRpt.Export False
If Err.Number <> 0 Then
'MsgBox "Error Occurred Exporting Report: " & Err.Description & Err.number
oRp = Nothing
oApp = Nothing
Else
If IsObject(oPageEngine) Then
Set oPageEngine = Nothing
End If
Set oPageEngine = oRpt.PageEngine
End If
End Sub