'// Declare the Crystal Application Object that will be used for this application.
Private CR_Application As CRAXDDRT.Application
'// Declare the Crystal Report object that will be used for the MAIN report.
Private CR_Report As CRAXDDRT.Report
'// Declare the Crystal Database, DatabaseTables and DatabaseTable objects.
Private CR_Db As CRAXDDRT.Database
Private CR_DbTables As CRAXDDRT.DatabaseTables
Private CR_DbTable As CRAXDDRT.DatabaseTable
Private Sub Print_Report(pReport As String, pPreview As Boolean)
'// Parameters:
'// pReport - the name of the report to be used (Full path required).
'// pPreview - Determines whether the report is previewed or sent to the printer.
Dim prn As Printer
Dim frmQ As Form
'// The following creates the Application object (which is the Crystal
'// Automation Server) and assigns it to CrystalApplication.
'// Creating this object must be done for each application that uses the Crystal Automation Server.
'// If this is to be related to using the ActiveX or OCX control, this following
'// method would be thought of as simply placing the control onto the VB form.
Set CR_Application = New CRAXDDRT.Application
'// The following sets the database location for all tables that are used in the report
Set CR_Report = CR_Application.OpenReport(pReport, 1)
Set CR_Db = CR_Report.Database
Set CR_DbTables = CR_Db.Tables
Set CR_DbTable = CR_DbTables.Item(1)
...
'(NOTE: I use ttx files and ttx information is placed here)
CR_Report.SelectPrinter prn.DriverName, prn.DeviceName, prn.Port
CR_Report.PaperSize = crDefaultPaperSize
CR_Report.PaperSource = crPRBinAuto
If pPreview Then
'// Previews the report on the screen.
Set frmQ = New frmViewer
frmQ.Initialize_Report CR_Report, "Report Title"
Else
'// Sends the report to the printer
CR_Report.PrintOut False
End If
End Sub