How to Show Printer Dialog Box-VBForums
Results 1 to 12 of 12

Thread: How to Show Printer Dialog Box

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    4

    How to Show Printer Dialog Box

    Hi Guys,

    How to show Printer Dialog Box From Visual Basic 6.0

    Users of the program must be able to select the printer where they want the output to be printed.

    Based on the user selection, program has to select the destination printer.

    Please help me on how to handle this requirement

    Rgds
    Nags

  2. #2
    Addicted Member Beasts's Avatar
    Join Date
    Oct 2006
    Posts
    147

    Re: How to Show Printer Dialog Box

    [QUOTE]um....have you tried the common dialog control?

  3. #3
    Hyperactive Member Fedhax's Avatar
    Join Date
    Aug 2006
    Posts
    293

    Re: How to Show Printer Dialog Box

    Quote Originally Posted by NagsITR
    How to show Printer Dialog Box From Visual Basic 6.0

    Users of the program must be able to select the printer where they want the output to be printed.

    Based on the user selection, program has to select the destination printer.
    The API call you want is PrintDialog. Once they select the printer, Windows will handle routing the document to be printed to the selected printer.

  4. #4
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: How to Show Printer Dialog Box

    VB Code:
    1. 'To show list of printers (not print dialog)
    2. 'Alternative way (without using API):
    3.  
    4. Option Explicit
    5.  
    6. 'Create a new project with a combo box (name: cboPrinter) and two
    7. 'command buttons (name: cmdSelect, Name: cmdPrint)
    8.  
    9. ' Return True if there is a problem.
    10. Private Function SelectPrinter(ByVal printer_name As String) As Boolean
    11.     Dim i As Integer
    12.  
    13.     SelectPrinter = True
    14.     For i = 0 To Printers.Count - 1
    15.         If Printers(i).DeviceName = printer_name Then
    16.             Set Printer = Printers(i)
    17.             SelectPrinter = False
    18.             Exit For
    19.         End If
    20.     Next i
    21. End Function
    22.  
    23. Private Sub cboPrinter_Click()
    24.     cmdSelect.Enabled = (cboPrinter.ListIndex >= 0)
    25. End Sub
    26.  
    27. Private Sub cmdPrint_Click()
    28.     On Error GoTo PrintError
    29.  
    30.     Printer.Line (1 * 1440, 1 * 1440)-(4.35 * 1440, 2 * 1440)
    31.     Printer.CurrentX = 1.25 * 1440
    32.     Printer.CurrentY = 1.25 * 1440
    33.     With Printer.Font
    34.         .Name = "Times New Roman"
    35.         .Size = 24
    36.     End With
    37.     Printer.Print "The quick brown fox jumps over the lazy dog"
    38.     Printer.EndDoc
    39.     MsgBox "Ok"
    40.     Exit Sub
    41.  
    42. PrintError:
    43.     MsgBox "Error " & Format$(Err.Number) & " printing." & _
    44.            vbCrLf & Err.Description
    45.     Exit Sub
    46. End Sub
    47.  
    48. Private Sub cmdSelect_Click()
    49.     If SelectPrinter(cboPrinter.Text) Then
    50.         MsgBox "Printer not found"
    51.     Else
    52.         cmdSelect.Enabled = False
    53.         cmdPrint.Enabled = True
    54.     End If
    55. End Sub
    56.  
    57. Private Sub Form_Load()
    58.     Dim i As Integer
    59.  
    60.     cboPrinter.Clear
    61.     For i = 0 To Printers.Count - 1
    62.         cboPrinter.AddItem Printers(i).DeviceName
    63.     Next i
    64.    
    65.     cmdSelect.Caption = "Select"
    66.     cmdPrint.Caption = "Print"
    67. End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    4

    Re: How to Show Printer Dialog Box

    Quote Originally Posted by Fedhax
    The API call you want is PrintDialog. Once they select the printer, Windows will handle routing the document to be printed to the selected printer.

    Hi, Can You can explain the same with a sample VB code.

    I saw this API in API List, however I don't know to handle the same.

    Rgds
    Nags

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    4

    Re: How to Show Printer Dialog Box

    Hi, Iam aware of this code..Thanx

  7. #7
    Hyperactive Member Hassan Basri's Avatar
    Join Date
    Sep 2006
    Posts
    306

    Re: How to Show Printer Dialog Box

    I have created a VB project with one command button that displays the Print Dialog.
    Attached Files Attached Files

  8. #8
    New Member
    Join Date
    Feb 2008
    Posts
    2

    Re: How to Show Printer Dialog Box

    Hassan's print dialog project works great. The only question that
    I have on it is how can you tell if the user presses cancel. I didn't
    see the cancel error in your code.

    Thanks

  9. #9
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: How to Show Printer Dialog Box

    Welcome to the forums.

    What do you need to do is the user presses cancel?
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  10. #10
    New Member
    Join Date
    Feb 2008
    Posts
    2

    Re: How to Show Printer Dialog Box

    Thanks Hack,

    I solved my problem by using the new vb print dialog (printdlg.dll) from
    Microsoft. This version will not change the windows default printer which
    was my original problem. This DLL will also return an error code if the user
    clicks the cancel button so that the printing sub is exited before printing
    occurs.

    Here is the link for the new printdlg.dll
    support.microsoft.com/kb/322710/en-us

    Thanks Again!

  11. #11
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: How to Show Printer Dialog Box

    No problem, and once again, welcome aboard.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  12. #12
    Junior Member
    Join Date
    Apr 2009
    Posts
    16

    Re: How to Show Printer Dialog Box

    Quote Originally Posted by Hassan Basri View Post
    I have created a VB project with one command button that displays the Print Dialog.
    But when we press print button it dose not print any thing

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.