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
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)
'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.