Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

export report to pdf then send to printer in vbscript

Status
Not open for further replies.

dgr01

IS-IT--Management
Apr 9, 2003
17
US
I m trying to export a crystal report (developed in Crystal 11) and in the same vbscript have that report sent to a network printer. Is there another option for destinationType = printer or do you know of a better way to accomplish this?

below is the code that works that send my report to a pdf file.

'-- Set Export Options
orpt.ExportOptions.DestinationType = 1 '-- to file
orpt.ExportOptions.PDFExportAllPages = True
orpt.ExportOptions.FormatType = 31 '-- to PDF
orpt.DiscardSavedData
If rptParamaterField <> "" then
oRpt.ParameterFields.GetItemByName("Extract Date").AddCurrentValue(rptDate)
End if
orpt.VerifyOnEveryPrint = True
orpt.ExportOptions.DiskFileName = rptDir & rptName &".pdf"
orpt.Export (False)

' Now i want to add code that automatically sends to the report to a network printer (\\lghdns3\boclp3)

any thoughts on this?
Thanks, dgr
 
Try translating this VB6 code to VBScript:
--------------------------------------------
Public Function Print_Report(Printer_Name As String, _
PromptUser As Boolean, _
NbrCopies As Long, _
Collated As Boolean, _
Optional StartPageN, Optional StopPageN) As Boolean
'Current Report Must be Opened
Dim sPaperOrientation As String
Dim sPaperSize As String
Dim sPaperSource As String
Dim sPrinterDriver As String
Dim sPrinterPort As String
Dim lStartPage As Long
Dim lStopPage As Long

On Error GoTo Print_Report_EH
sPrinterDriver = GetPrinterDriver(Printer_Name)
If sPrinterDriver = "" Then 'Printer not found on this server's list of printers
Err.Raise -999, "clsCCrysRun.Print_Report", "Printer '" & Printer_Name & "' not found on this server's list of printers"
Print_Report = False
Exit Function
End If
sPrinterPort = GetPrinterPort(Printer_Name)
If Not IsMissing(StartPageN) Then lStartPage = StartPageN
If Not IsMissing(StopPageN) Then lStopPage = StopPageN
If lStopPage > 0 And lStartPage = 0 Then lStartPage = 1

With crReport
'Save off properties that are are overlaid by .SelectPrinter
sPaperOrientation = .PaperOrientation
sPaperSize = .PaperSize
sPaperSource = .PaperSource
.SelectPrinter sPrinterDriver, Printer_Name, sPrinterPort
.PaperOrientation = sPaperOrientation
.PaperSize = sPaperSize
.PaperSource = crPRBinAuto
If lStartPage > 0 Then
.PrintOut PromptUser, NbrCopies, Collated, lStartPage, lStopPage
Else
.PrintOut PromptUser:=PromptUser, numberofcopy:=NbrCopies, Collated:=Collated
End If
End With
Exit Function

Function GetPrinterDriver(PrinterName As String) As String
'Returns Printer Driver Name or "" if printer not found
Dim PrinterX As Printer

For Each PrinterX In Printers
If UCase(PrinterX.DeviceName) = UCase(PrinterName) Then
GetPrinterDriver = PrinterX.DriverName
Exit Function
End If
Next
GetPrinterDriver = ""
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top