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!

Change Printer in VB - HELP!

Status
Not open for further replies.

cturland

Programmer
Sep 25, 2000
66
GB
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%
 
Maybe try the CHR$(0) - for example:


driverName$ = idriver + Chr$(0)
printerName$ = iprinter + Chr$(0)
portName$ = iport + Chr$(0)

If PESelectPrinter(Jobnum, driverName$, printerName$, portName$, 0) = False Then
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top