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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programming Crystal Reports in VB - HELP!

Status
Not open for further replies.

cturland

Programmer
Sep 25, 2000
66
GB
Hi all,

I 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%
 
Do you trying to use Crystal Report Control or CRViewer Control ?
If you are using CR Control you can set properties like PrinterName, PrinterDriver, PrinterPort.
If you are using CRViewer you can write code on PrintButtonClicked event
Hope this is helpful.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top