Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Business Objects: Crystal Reports 4 Other topics FAQ

Common Formulas

How to setup printers + properties in VB by cturland
Posted: 20 Mar 01

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%

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)

'===================Setup Printer==================
PrtDriver$ = Printers(curprinter%).driverName & vbNullChar

PrtName$ = Printers(curprinter%).DeviceName & vbNullChar

PrtPort$ = Printers(curprinter%).Port & vbNullChar

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

Response% = crPESelectPrinter(jobNo%, PrtDriver$, PrtName$, PrtPort$, PrtSet)

'Print the report and close the printer
Response% = PEOutputToPrinter(jobNo%, 1)
Response% = PEStartPrintJob(jobNo%, True)
Response% = PEClosePrintJob(jobNo%)

End Sub

Back to Business Objects: Crystal Reports 4 Other topics FAQ Index
Back to Business Objects: Crystal Reports 4 Other topics Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close