This is a working example of printing a saved Crystal Report. You need to add the Crystal Report references to your project:
VB Code:
Private Sub Command1_Click()
'Print a saved Crytal Report
'Visual Basic 6.0
'Crystal reports 8.0
Dim rsTempRecordset As New ADODB.Recordset
Dim CR_CustomApp As New CRAXDRT.Application
Dim CR_CustomReport As CRAXDRT.Report
Dim prn As Printer
'Using SQL 2000
With cnCMS
.CursorLocation = adUseClient
.ConnectionString = "MSDASQL.1;" & _
"Persist Security Info=True;" & _
"User ID=sa;" & _
"Password='';" & _
"Data Source=CMS"
.Open
End With
'You can use the data saved with the report. I want it fresh everytime.
With rsTempRecordset
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = cnCMS
.LockType = adLockOptimistic
.Source = "Select * from ScanDocumentsErrors "
.Open
End With
Set CR_CustomReport = CR_CustomApp.OpenReport("c:\@@crystal\TwainReport.rpt", 1)
'Use can use the printer saved with the report and skip this part. Or
'use the loop to display the printer avaiable to you. Mine were:
' Availble Printer names:
' TPA
' Federal
' hp LaserJet
' State
For Each prn In Printers
If prn.DeviceName Like "*LaserJet*" Then
Set Printer = prn
Exit For
End If
Next
CR_CustomReport.SelectPrinter prn.DriverName, prn.DeviceName, prn.Port
'Get rid of saved date
CR_CustomReport.DiscardSavedData
'Use can use the orientation saved with the report or override it.
'DefaultPaperOrientation = 0
'Portrait = 1
'Landscape = 2
CR_CustomReport.PaperOrientation = 2
CR_CustomReport.Database.SetDataSource rsTempRecordset
CR_CustomReport.PrintOut False
Set CR_CustomReport = Nothing
Set rsTempRecordset = Nothing
cnCMS.Close
End Sub