Click to See Complete Forum and Search --> : Scheduling Crystal Report Using VB Script


sudkool
December 8th, 2008, 03:59 PM
Hi,

I haven't wrote a vbscript in my life but got new requirement to scheudule my Crystal Reports using VBScript. I did some research online and found a sample code. I updated the code according to my requirement and try to execute it but it is giving me an error message (attached). I am not sure what I am doing wrong. I will really really appreciate if someone could take a look at it and let me know what I am doing wrong.

Thank so much in advance.

~Samir

CODE:


Dim sReportName 'As String
Dim PrintToScreen 'As Boolean
Dim iNumToPrint 'As Integer
Dim View1 'As CRPEAuto.View

Dim CRapp 'As CRPEAuto.Application
Dim report 'As CRPEAuto.report
Dim Window1 'As CRPEAuto.Window
Dim reportDb 'As CRPEAuto.Database
Dim reportTables 'As CRPEAuto.DatabaseTables
Dim reportTable 'As CRPEAuto.DatabaseTable
sReportName = "MyTestReport.rpt"
iNumToPrint = 1
'Create an Application object with the Crystal Report Engine Automation
Server.
Set CRapp = WScript.CreateObject("Crystal.CRPE.Application")

'Obtain a Report object by opening the report file
Set report = CRapp.OpenReport(sReportName)

Set reportDb = report.Database
Set reportTables = reportDb.Tables
Set reportTable = reportTables.Item(1)


'Use Crystals to attempts to prompt for parameters
report.ParameterPromptingEnabled = True

'Tell Crystal what it needs to know to connect to the table below is te
test info

Call reportTable.SetLogOnInfo("ServerName", "SchemaName", "UserName", "Password")

report.PrintWindowOptions.HasPrintSetupButton = True
report.PrintWindowOptions.HasPrintSetupButton = True
report.PrintWindowOptions.HasExportButton = True
report.PrintWindowOptions.HasSearchButton = True
report.PrintWindowOptions.HasCancelButton = True
report.PrintWindowOptions.HasCloseButton = True
report.PrintWindowOptions.HasRefreshButton = True
report.PrintWindowOptions.HasGroupTree = True
report.PrintWindowOptions.HasNavigationControls = True
report.PrintWindowOptions.HasProgressControls = True
report.preview

'************************************************* ******************
If report.LastErrorString = "" Or report.LastErrorString = "No eror."
Then
'printing
Else
MsgBox "Error in crystal reports : " & report.LastErrorString,
vbCritical
End If

On Error Resume Next
Set CRapp = Nothing
Set report = Nothing
Set reportDb = Nothing
Set reportTables = Nothing
Set reportTable = Nothing