Here is a example of how to setup printers for reports in runtime and how to use Devmode to set its properties. First a list box is populated with all the available printers to the computer and allows the user to select which printer to print from and which printer bin to use.......
Private Sub 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
End Sub
Private Sub cmdPrintReport_Click()
Dim PrtSet As crDEVMODE ' Declare a DevMode
'Get the printer selected in the index
curprinter% = lstPrintList.ListIndex
'Find the report
reportFilePath = txtReportPath.Text
'Open the print engine
Result% = PEOpenEngine()
'Setup PrtSet settings - Only using Orientation and DefaultSource
With PrtSet
.dmFields = &H200 Or &H1 'dmFields has to be set to what properties are being used in DEVMODE
.dmDefaultSource = Int(txtBinNo.Text)
.dmOrientation = DMORIENT_LANDSCAPE
End With
'Open the report file for printing
jobNo% = PEOpenPrintJob(reportFilePath)
[Color Red]'crPESelectPrinter function has to be used instead of PESelectPrinter function in VB due to VB32bit using 4-byte alignment whereas the CR print engine uses 1-byte alignment. The crPESelectPrinter function calls PESelectPrinter in a C++ 1-byte alignment enviroment, bypassing VB.[/color]
'Print the report and close the printer
Response% = PEOutputToPrinter(jobNo%, 1)
Response% = PEStartPrintJob(jobNo%, True)
Response% = PEClosePrintJob(jobNo%)
PECloseEngine
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.