INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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.

Jobs

CR Printer Dialog Box

How to bypass CR Print API to select printer properties... by bburnell
Posted: 21 Dec 00

1. In your CR Viewer form. In the "properties" window, change "EnablePrintButton" to "false"

2. Now you must add a print command button. Call it "cmdPrint"

3. Now add the following code to your CR Viewer form:

Private Sub cmdPrint_Click()
    '*** following code can be manipulated ***
    If (Len(sPrintMsg) > 0) Then
        MsgBox sPrintMsg, , App.ProductName & " Print Request"
        sPrintMsg = ""
    End If

    '*** Object reference to the VB Printer Object ***
    Load frmPrinterSetup
    frmPrinterSetup.Show
End Sub


4. Create new form named "frmPrinterSetup"
   - This form is loosely based off of sample code from CR8. It can be found in:
    C:/Seagate Software/Samples/Code/Visual Basic/Printer Settings/*.*
   - It is form frmMain.

5. Add the following code to "frmPrinterSetup":

Private Sub Form_Load()
    '*** Return the Printer Information saved with the Report ***
    '***         Set page to show the default printer         ***

    If (cmbPrinters.List(cmbPrinters.ListIndex) = spaces) Then
        cmbPrinters.Text = Printer.DeviceName
    End If
    lblPrinterDriver2.Caption = Printer.DriverName
    lblPrinterPort2.Caption = Printer.Port

    '*** Display the Paper Size of the report ***
    Select Case MyRpt.PaperSize
    Case 1
        TxtPaperSize.Text = "Letter, 8 1/2"" x 11"""
    Case 2
        TxtPaperSize.Text = "Letter Small, 8 1/2"" x 11"""
    Case 3
        TxtPaperSize.Text = "Tabloid, 11"" x 17"""
    Case 4
        TxtPaperSize.Text = "Ledger, 17"" x 11"""
    Case 5
        TxtPaperSize.Text = "Legal, 8 1/2"" x 14"""
    Case 6
        TxtPaperSize.Text = "Statement, 5 1/2"" x 8 1/2"""
    Case 7
        TxtPaperSize.Text = "Executive, 7 1/2"" x 10 1/2"""
    Case 8
        TxtPaperSize.Text = "A3, 297 x 420 mm"
    Case 9
        TxtPaperSize.Text = "A4, 210 x 297 mm"
    Case 10
        TxtPaperSize.Text = "A4 Small, 210 x 297 mm"
    Case 11
        TxtPaperSize.Text = "A5, 148 x 210 mm"
    Case 12
        TxtPaperSize.Text = "B4, 250 x 354 mm"
    Case 13
        TxtPaperSize.Text = "B5, 182 x 257 mm"
    Case 14
        TxtPaperSize.Text = "Folio, 8 1/2"" x 13"""
    Case 15
        TxtPaperSize.Text = "Quarto, 215 x 275 mm"
    Case 16
        TxtPaperSize.Text = "10"" x 14"""
    Case 17
        TxtPaperSize.Text = "11"" x 17"""
    Case 18
        TxtPaperSize.Text = "Note, 8 1/2"" x 11"""
    Case 19
        TxtPaperSize.Text = "Envelope #9, 3 7/8"" x 8 7/8"""
    Case 20
        TxtPaperSize.Text = "Envelope #10, 4 1/8"" x 9 1/2"""
    Case 21
        TxtPaperSize.Text = "Envelope #11, 4 1/2"" x 10 3/8"""
    Case 22
        TxtPaperSize.Text = "Envelope #12, 4 1/2"" x 11"""
    Case 23
        TxtPaperSize.Text = "Envelope #14, 5"" x 11 1/2"""
    Case 24
        TxtPaperSize.Text = "C size sheet"
    Case 25
        TxtPaperSize.Text = "D size sheet"
    Case 26
        TxtPaperSize.Text = "E size sheet"
    Case 27
        TxtPaperSize.Text = "Envelope DL, 110 x 220 mm"
    Case 28
        TxtPaperSize.Text = "Envelope C5, 162 x 229 mm"
    Case 29
        TxtPaperSize.Text = "Envelope C3, 324 x 458 mm"
    Case 30
        TxtPaperSize.Text = "Envelope C4, 229 x 324 mm"
    Case 31
        TxtPaperSize.Text = "Envelope C6, 114 x 162 mm"
    Case 32
        TxtPaperSize.Text = "Envelope C65, 114 x 229 mm"
    Case 33
        TxtPaperSize.Text = "Envelope B4, 250 x 353 mm"
    Case 34
        TxtPaperSize.Text = "Envelope B5, 176 x 250 mm"
    Case 35
        TxtPaperSize.Text = "Envelope B6, 176 x 125 mm"
    Case 36
        TxtPaperSize.Text = "Envelope, 110 x 230 mm"
    Case 37
        TxtPaperSize.Text = "Envelope Monarch, 3 7/8"" x 7 1/2"""
    Case 38
        TxtPaperSize.Text = "Envelope, 3 5/8"" x 6 1/2"""
    Case 39
        TxtPaperSize.Text = "U.S. Standard Fanfold, 14 7/8"" x 11"""
    Case 40
        TxtPaperSize.Text = "German Standard Fanfold, 8 1/2"" x 12"""
    Case 41
        TxtPaperSize.Text = "German Legal Fanfold, 8 1/2"" x 13"""
    Case 256
        TxtPaperSize.Text = "User-defined"
    Case Else
        TxtPaperSize.Text = "Default"
    End Select

    '*** Display the Paper Orientation of the report ***
    Select Case MyRpt.PaperOrientation
    Case crLandscape
        '*** Report is set to "Landscape" orientation ***
        optLandscape.Value = True
    Case Else
        '*** Default to "Portrait" orientation ***
        optPortrait.Value = True
    End Select

    '*** Display the Printer Duplex of the report ***
    optDDefault.Value = True

    '*** Return all of the Printers that are installed on the target machine ***
    For Each mPrinter In Printers
        cmbPrinters.AddItem mPrinter.DeviceName
        lstDeviceName.AddItem mPrinter.DeviceName
        lstDriverName.AddItem mPrinter.DriverName
        lstPort.AddItem mPrinter.Port
    Next
End Sub

Private Sub cmbPrinters_Click()
    '*** Set the printer to the user default Device  ***
    '*** if no printer was selected in the combo box ***

    If (cmbPrinters.List(cmbPrinters.ListIndex) = spaces) Then
        cmbPrinters.Text = Printer.DeviceName
    End If

    '*** Set the printer to the user default Driver  ***
    '*** if no printer was selected in the combo box ***

    If (lstDriverName.List(cmbPrinters.ListIndex) = spaces) Then
        lblPrinterDriver2.Caption = Printer.DriverName
    Else
        lblPrinterDriver2.Caption = lstDriverName.List(cmbPrinters.ListIndex)
    End If

    '***  Set the printer to the user default Port   ***
    '*** if no printer was selected in the combo box ***

    If (lstPort.List(cmbPrinters.ListIndex) = spaces) Then
        lblPrinterPort2.Caption = Printer.Port
    Else
        lblPrinterPort2.Caption = lstPort.List(cmbPrinters.ListIndex)
    End If
End Sub

Private Sub cmdOK_Click()
    '*** Set the printer to the user default Device  ***
    '*** if no printer was selected in the combo box ***

    If (cmbPrinters.List(cmbPrinters.ListIndex) = spaces) Then
        pname = Printer.DeviceName
    Else
        pname = cmbPrinters.List(cmbPrinters.ListIndex)
    End If

    '***  Set the printer to the user default Port   ***
    '*** if no printer was selected in the combo box ***

    If (lstPort.List(cmbPrinters.ListIndex) = spaces) Then
        pport = Printer.Port
    Else
        pport = lstPort.List(cmbPrinters.ListIndex)
    End If

    '*** Set the printer to the user default Driver  ***
    '*** if no printer was selected in the combo box ***

    If (lstDriverName.List(cmbPrinters.ListIndex) = spaces) Then
        pdriver = Printer.DriverName
    Else
        pdriver = lstDriverName.List(cmbPrinters.ListIndex)
    End If

    '*** Call the "SelectPrinter" CRAPI (Crystal Reports API) ***
    Call MyRpt.SelectPrinter(pdriver, pname, pport)

    '+++++++++++++ All the following attributes MUST be done +++++++++++++
    '+++++++++++++    after the printer has been selected    +++++++++++++

    '*** Set the Orientation of the Report ***

    If (optLandscape = True) Then
        '*** "Landscape" Orientation Selected ***
        MyRpt.PaperOrientation = crLandscape
    ElseIf (optPortrait = True) Then
        '*** "Portrait" Orientation Selected ***
        MyRpt.PaperOrientation = crPortrait
    Else
        '*** Default Orientation Selected ***
        MyRpt.PaperOrientation = crDefaultPaperOrientation
    End If

    '*** Set the Duplex of the Report ***
    If (optDNone = True) Then
        '*** Selection is 1 [NONE] ***
        MyRpt.PrinterDuplex = crPRDPSimplex
    ElseIf (optDLong = True And optPortrait = True) Or _
     (optDShort = True And optLandscape = True) Then
        '*** Selection is 2 [LONG SIDE] ***
        MyRpt.PrinterDuplex = crPRDPVertical
    ElseIf (optDShort = True And optPortrait = True) Or _
     (optDLong = True And optLandscape = True) Then
        '*** Selection is 3 [SHORT SIDE] ***
        MyRpt.PrinterDuplex = crPRDPHorizontal
    'Else (*** Selection is [DEFAULT] ***)
        'MyRpt.PrinterDuplex = crPRDPDefault

    End If

    '*** Sends the Report to the Printer ***
    Unload Me
    MyRpt.PrintOut
End Sub

Private Sub cmdCancel_Click()
    Unload frmPrinterSetup
End Sub


NOTES:
Obviously this is a crude representation of what I did, but enough to get you started. You can play with it to do many things. You can even change the code to be able to change paper size and orientation! It currently defaults to whatever is set in the Crystal Report DSR. My CR Viewer is also set up in this example to handle multiple Crystal Reports with the one form. So your coding may have to be tweaked. I hope this helps! You may email me with questions (please be patient for an answer...)

Brett
brett_burnell@email.com
http://www.smsforce.com
http://www.goodguyz.com

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

My Archive

Resources

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