Hi all,
I'm really am stuck on trying to get Crystal Reports to change the printer in VB. This is the code I am using but it always returns an error - any ideas??! I first populate a list box with all the available printers and then allow the user to select one. Any help would be really appreciated!
==================ON FORM LOAD=======================
Dim PrintData As Printer
For Each PrintData In Printers
' Add printer name and port to list
lstPrintList.AddItem PrintData.DeviceName & " at " & PrintData.Port
' Check for default printer
If PrintData.DeviceName = Printer.DeviceName Then defprinterpos% = lstPrintList.NewIndex
lstPrintList.ListIndex = defprinterpos%
Next
=================ON PRINT CLICK=======================
curprinter% = lstPrintList.ListIndex
reportFilePath = "d:\Blah.rpt"
PEOpenEngine
JobNo% = PEOpenPrintJob(reportFilePath)
PEOutputToPrinter JobNo%, 1
If Err = crPESelectPrinter(JobNo%, Printers(curprinter%).driverName, Printers(curprinter%).DeviceName, Printers(curprinter%).Port, mode) = 0 Then
MsgBox ("Printer Error!"
Exit Sub
End If
PEStartPrintJob JobNo%, True
PEClosePrintJob JobNo%
I'm really am stuck on trying to get Crystal Reports to change the printer in VB. This is the code I am using but it always returns an error - any ideas??! I first populate a list box with all the available printers and then allow the user to select one. Any help would be really appreciated!
==================ON FORM LOAD=======================
Dim PrintData As Printer
For Each PrintData In Printers
' Add printer name and port to list
lstPrintList.AddItem PrintData.DeviceName & " at " & PrintData.Port
' Check for default printer
If PrintData.DeviceName = Printer.DeviceName Then defprinterpos% = lstPrintList.NewIndex
lstPrintList.ListIndex = defprinterpos%
Next
=================ON PRINT CLICK=======================
curprinter% = lstPrintList.ListIndex
reportFilePath = "d:\Blah.rpt"
PEOpenEngine
JobNo% = PEOpenPrintJob(reportFilePath)
PEOutputToPrinter JobNo%, 1
If Err = crPESelectPrinter(JobNo%, Printers(curprinter%).driverName, Printers(curprinter%).DeviceName, Printers(curprinter%).Port, mode) = 0 Then
MsgBox ("Printer Error!"
Exit Sub
End If
PEStartPrintJob JobNo%, True
PEClosePrintJob JobNo%