CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2002
    Posts
    72

    Printer problems

    I am trying to allow a user to select a printer to print out a crystal designer report without changing the default printer setting. The code below works great for the print job but it changes the default printer to what is selected. I tried various approaches mentioned here at Codeguru but none of them are shifting the printer back to the original default. What’s strange about this is if I put a msgbox in the code to see if the Printer object is back to the default it is but not when you then look in settings or re-open the common dialog box. Also, for some reason the Printer object has a different port designation than that which comes from the Printers collection. Only the latter will work with the SelectPrinter method. Maybe a totally different approach would be better.

    Private Sub CRViewer1_PrintButtonClicked(UseDefault As Boolean)

    UseDefault = False
    On Error GoTo CancelError
    CommonDialog1.CancelError = True

    'needs to be True to set Printer Object
    CommonDialog1.PrinterDefault = True
    CommonDialog1.ShowPrinter

    'get proper port designation
    Dim prt As Printer
    For Each prt In Printers
    If prt.DeviceName = Printer.DeviceName Then
    Dim a As String
    Dim B As String
    Dim C As String
    a = prt.DriverName
    B = prt.DeviceName
    C = prt.Port
    crxReport9.SelectPrinter a, B, C
    Exit For
    End If
    Next

    crxReport9.PrintOut False
    Printer.EndDoc

    '''’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
    ‘Restore default printer
    'Need Help here.
    ‘if use Printers collection to get the original default printer and
    ‘then state Set Printer = originaldefaultprinter the Printer object
    ‘is set but not the System Printer.
    ''''''''''''''''''''''''''''’’’’’’’’’’’’’’’’’’’’’

    Exit Sub

    CancelError:
    MsgBox "Printing Canceled"

    End Sub

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Printer problems - NEW CDC CONTROL

    Try this instead:
    Attached Files Attached Files
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jun 2007
    Posts
    5

    Re: Printer problems

    ' Copy user input from the dialog box to the properties of the selected printer.
    printDlg.Copies = Printer.Copies
    printDlg.Orientation = Printer.Orientation
    printDlg.ColorMode = Printer.ColorMode
    printDlg.Duplex = Printer.Duplex
    printDlg.PaperBin = Printer.PaperBin
    printDlg.PaperSize = Printer.PaperSize
    printDlg.PrintQuality = Printer.PrintQuality

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured