Results 1 to 9 of 9

Thread: select printer

  1. #1
    Join Date
    Feb 2009
    Posts
    23

    Unanswered: select printer

    I am using Crystal report XI for my reports. On my program i want to let the user to select a printer he/she wants.

    my code is this
    Dim Report As New CRconPerm 'CRconPerm is my report added to Designer

    With Report
    .RecordSelectionFormula = "{Check_Delivery.DR_Number} = '" + dr_number.Text + "'"
    .PaperOrientation = crPortrait
    .PrintOut False
    End With

    when i try to add .SelectPrinter i am having an error.

  2. #2
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    and the error is... ?
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  3. #3
    Join Date
    Feb 2009
    Posts
    23

    error

    Compile Error:Argument not optional.

    i saw this in object browser.
    Sub SelectPrinter(pDriverName As String, pPrinterName As String, pPortName As String)

    so i believe that i have to declare its driver,printername and port name.
    if thats the case, how can i let the user to pick his/her desire printer?

  4. #4
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Use the common dialog control -the .ShowPrinter method. The user selects a printer, and when they exit, the common dialog control has set the printer to the one chosen by the user.

    Here's a test. On a blank project, add a common dialog control, named cDialog, and a command button, named cmdButton. Then, open the code editor, and paste this code there:
    Code:
    Option Explicit
    
    Private Sub cmdButton_Click()
       
       Printer.Font.Size = 10
       Printer.ForeColor = vbBlack
       Printer.Print "*** Before ShowPrinter ***"
       Printer.Print "Printer DeviceName: " & Printer.DeviceName
       Printer.Print "Printer Port: " & Printer.Port
       Printer.Print "Printer DriverName: " & Printer.DriverName & vbNewLine
       
       Me.cDialog.ShowPrinter
       
       Printer.Print "*** After ShowPrinter ***"
       Printer.Print "Printer DeviceName: " & Printer.DeviceName
       Printer.Print "Printer Port: " & Printer.Port
       Printer.Print "Printer DriverName: " & Printer.DriverName
       Printer.Print "Copies: " & Me.cDialog.Copies
       Printer.Print "Orientation: " & Me.cDialog.Orientation
    
       Printer.Font.Size = 48
       Printer.ForeColor = vbRed
       Printer.Print "Test"
       
       Printer.Font.Size = 10
       Printer.ForeColor = vbBlack
       
       Printer.EndDoc
    
    End Sub
    For more info, ref msdn.
    Last edited by loquin; 03-05-09 at 19:05.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  5. #5
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Note: the shortcoming with this approach is that the default printer is usually changed in the process, so, you'll want to save the current printer before this code, and reset the default printer after you're done.

    Here's the code to save the current default printer:
    Code:
    Dim prn as vb.printer
    Dim dflt_prn as vb.Printer
    
    set dflt_prn = Printer
    Unfortunately, you can't simply reassign the default printer this way, so, to restore the default printer
    Code:
       'restore the default printer
       For Each prn In VB.Printers
          If prn.DeviceName = dflt_prn.DeviceName Then
             Set Printer = prn
          End If
       Next prn
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  6. #6
    Join Date
    Feb 2009
    Posts
    23

    Talking try

    i try your code. i am having logical error.

    before the common dialog show my printer is epson
    then after the common dialog show my printer is OneNote

    on my print out OneNote is my printer Before and After the common dialog show.

    but anyway its a challenge for me to debug or to know where the error is

    right now i use some of your code to load the available printers on a combobox.

    i learn vb.printer

    thanks

  7. #7
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    are you using VB6, or VB.Net? My answer was for VB6.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  8. #8
    Join Date
    Feb 2009
    Posts
    23

    6.0

    i use vb6.0 Enterprise edition.

  9. #9
    Join Date
    Feb 2009
    Posts
    23
    Code:
    Option Explicit
    Dim prn As VB.Printer
    Dim dflt_prn As VB.Printer
    Private Sub cmdButton_Click()
       
       Printer.Print "*** Before ShowPrinter ***"
       Printer.Print "Printer DeviceName: " & dflt_prn.DeviceName
       Printer.Print "Printer Port: " & dflt_prn.Port
       Printer.Print "Printer DriverName: " & dflt_prn.DriverName
       Printer.EndDoc
    
       Me.cDialog.ShowPrinter
       
       Printer.Print "*** After ShowPrinter ***"
       Printer.Print "Printer DeviceName: " & Printer.DeviceName
       Printer.Print "Printer Port: " & Printer.Port
       Printer.Print "Printer DriverName: " & Printer.DriverName
       Printer.Print "Copies: " & Me.cDialog.Copies
       Printer.Print "Orientation: " & Me.cDialog.Orientation
       Printer.EndDoc
       
       'restore the default printer
       For Each prn In VB.Printers
       If prn.DeviceName = dflt_prn.DeviceName Then
           Set Printer = prn
       End If
       Next prn
       
    End Sub
    
    Private Sub Form_Load()
    Set dflt_prn = Printer
    MsgBox dflt_prn.DeviceName
    End Sub

Posting Permissions

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