Results 1 to 15 of 15

Thread: [RESOLVED] Printing Problems

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Resolved [RESOLVED] Printing Problems

    I'm having printing problems because I do not have the Microsoft VB Printer Dialog(PSS) aka (vbprndlg.dll) in my references-it's missing. Does anyone know where I can get it? Thanks.

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Printing Problems

    I've never heard of that reference before, what is it? Are you sure you need it?

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Printing Problems

    Quote Originally Posted by manofsteel00
    I'm having printing problems because I do not have the Microsoft VB Printer Dialog(PSS) aka (vbprndlg.dll) in my references-it's missing. Does anyone know where I can get it? Thanks.
    I just did a hard drive wide search of my machine, and I don't even have the file on my PC, but I've not had any printing issues.

    What are you trying to print and how are you trying to print it?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Printing Problems

    Ok here's the code:

    VB Code:
    1. Dim printDlg As PrinterDlg
    2.     Set printDlg = New PrinterDlg
    3.     ' Set the starting information for the dialog box based on the current
    4.     ' printer settings.
    5.     printDlg.PrinterName = Printer.DeviceName
    6.     printDlg.DriverName = Printer.DriverName
    7.     printDlg.Port = Printer.Port
    8.    
    9.     ' Set the default PaperBin so that a valid value is returned even
    10.     ' in the Cancel case.
    11.     printDlg.PaperBin = Printer.PaperBin
    12.    
    13.     ' Set the flags for the PrinterDlg object using the same flags as in the
    14.     ' common dialog control. The structure starts with VBPrinterConstants.
    15.     printDlg.Flags = VBPrinterConstants.cdlPDNoSelection _
    16.                      Or VBPrinterConstants.cdlPDNoPageNums _
    17.                      Or VBPrinterConstants.cdlPDReturnDC
    18.     Printer.TrackDefault = False
    19.    
    20.     ' When CancelError is set to True the ShowPrinterDlg will return error
    21.     ' 32755. You can handle the error to know when the Cancel button was
    22.     ' clicked. Enable this by uncommenting the lines prefixed with "'**".
    23.     '**printDlg.CancelError = True
    24.    
    25.     ' Add error handling for Cancel.
    26.     '**On Error GoTo Cancel
    27.     If Not printDlg.ShowPrinter(Me.hWnd) Then
    28.         Debug.Print "Cancel Selected"
    29.         Exit Sub
    30.     End If
    31.    
    32.     'Turn off Error Handling for Cancel.
    33.     '**On Error GoTo 0
    34.     Dim NewPrinterName As String
    35.     Dim objPrinter As Printer
    36.     Dim strsetting As String
    37.    
    38.     ' Locate the printer that the user selected in the Printers collection.
    39.     NewPrinterName = UCase$(printDlg.PrinterName)
    40.     If Printer.DeviceName <> NewPrinterName Then
    41.         For Each objPrinter In Printers
    42.            If UCase$(objPrinter.DeviceName) = NewPrinterName Then
    43.                 Set Printer = objPrinter
    44.            End If
    45.         Next
    46.     End If
    47.    
    48.     ' Copy user input from the dialog box to the properties of the selected printer.
    49.     Printer.Copies = printDlg.Copies
    50.     Printer.Orientation = printDlg.Orientation
    51.     Printer.ColorMode = printDlg.ColorMode
    52.     Printer.Duplex = printDlg.Duplex
    53.     Printer.PaperBin = printDlg.PaperBin
    54.     Printer.PaperSize = printDlg.PaperSize
    55.     Printer.PrintQuality = printDlg.PrintQuality
    56.    
    57.     ' Display the results in the immediate (Debug) window.
    58.     ' NOTE: Supported values for PaperBin and Size are printer specific. Some
    59.     ' common defaults are defined in the Win32 SDK in MSDN and in Visual Basic.
    60.     ' Print quality is the number of dots per inch.
    61.     With Printer
    62.         Debug.Print .DeviceName
    63.         If .Orientation = 1 Then
    64.             strsetting = "Portrait. "
    65.         Else
    66.             strsetting = "Landscape. "
    67.         End If
    68.         Debug.Print "Copies = " & .Copies, "Orientation = " & _
    69.            strsetting
    70.         If .ColorMode = 1 Then
    71.             strsetting = "Black and White. "
    72.         Else
    73.             strsetting = "Color. "
    74.         End If
    75.         Debug.Print "ColorMode = " & strsetting
    76.         If .Duplex = 1 Then
    77.             strsetting = "None. "
    78.         ElseIf .Duplex = 2 Then
    79.             strsetting = "Horizontal/Long Edge. "
    80.         ElseIf .Duplex = 3 Then
    81.             strsetting = "Vertical/Short Edge. "
    82.         Else
    83.             strsetting = "Unknown. "
    84.         End If
    85.         Debug.Print "Duplex = " & strsetting
    86.         Debug.Print "PaperBin = " & .PaperBin
    87.         Debug.Print "PaperSize = " & .PaperSize
    88.         Debug.Print "PrintQuality = " & .PrintQuality
    89.         If (printDlg.Flags And VBPrinterConstants.cdlPDPrintToFile) = _
    90.            VBPrinterConstants.cdlPDPrintToFile Then
    91.              Debug.Print "Print to File Selected"
    92.         Else
    93.              Debug.Print "Print to File Not Selected"
    94.         End If
    95.         Debug.Print "hDC = " & printDlg.hDC
    96.     End With
    97.     rtb.SelPrint printDlg.hDC
    98.     Exit Sub
    99.     '**Cancel:
    100.     '**If Err.Number = 32755 Then
    101.     '**    Debug.Print "Cancel Selected"
    102.     '**Else
    103.     '**    Debug.Print "A nonCancel Error Occured - "; Err.Number
    104.     '**End If
    I'm getting the "User defined Type not defined" error when creating the PrinterDlg object.

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Printing Problems

    Here's a link. It's a revised control from Microsoft that lets you use a CDC to print. It resolves issues with selecting the printer on the fly.

    http://support.microsoft.com/default...322710/EN-US/?

    SUMMARY
    You can use the Vbprndlg.dll file instead of the Print dialog box portion of the Visual Basic CommonDialog control. This file exposes properties and provides functionality that the CommonDialog control does not.

    The CommonDialog control in Visual Basic permits the Print dialog box to be displayed, but it does not give access to many of the properties that can be set in the Print dialog box and consumed by the Printer object. Because of alignment problems with structures (that is, user-defined types) when the Win32 application programming interface (API) functions are made from Visual Basic, you cannot reliably obtain additional information by using these API calls. As a workaround, this article provides a DLL that you can use instead of the Printer portion of the CommonDialog control.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Printing Problems

    I still have not gotten that code to work. It will pop up a screen and let me select a printer, but once I click print it does nothing. I'm also been trying to tweek this code:

    VB Code:
    1. Dim printDlg As PrinterDlg
    2. Set printDlg = New PrinterDlg
    3. ' Set the starting information for the dialog box based on the current
    4. ' printer settings.
    5. printDlg.PrinterName = Printer.DeviceName
    6. printDlg.DriverName = Printer.DriverName
    7. printDlg.Port = Printer.Port
    8.  
    9. ' Set the default PaperBin so that a valid value is returned even
    10. ' in the Cancel case.
    11. printDlg.PaperBin = Printer.PaperBin
    12.  
    13. ' Set the flags for the PrinterDlg object using the same flags as in the
    14. ' common dialog control. The structure starts with VBPrinterConstants.
    15. printDlg.Flags = VBPrinterConstants.cdlPDNoSelection _
    16.                  Or VBPrinterConstants.cdlPDNoPageNums _
    17.                  Or VBPrinterConstants.cdlPDReturnDC
    18. Printer.TrackDefault = False
    19.  
    20. ' When CancelError is set to True the ShowPrinterDlg will return error
    21. ' 32755. You can handle the error to know when the Cancel button was
    22. ' clicked. Enable this by uncommenting the lines prefixed with "'**".
    23. '**printDlg.CancelError = True
    24.  
    25. ' Add error handling for Cancel.
    26. '**On Error GoTo Cancel
    27. If Not printDlg.ShowPrinter(Me.hWnd) Then
    28.     Debug.Print "Cancel Selected"
    29.     Exit Sub
    30. End If
    31.  
    32. 'Turn off Error Handling for Cancel.
    33. '**On Error GoTo 0
    34. Dim NewPrinterName As String
    35. Dim objPrinter As Printer
    36. Dim strsetting As String
    37.  
    38. ' Locate the printer that the user selected in the Printers collection.
    39. NewPrinterName = UCase$(printDlg.PrinterName)
    40. If Printer.DeviceName <> NewPrinterName Then
    41.     For Each objPrinter In Printers
    42.        If UCase$(objPrinter.DeviceName) = NewPrinterName Then
    43.             Set Printer = objPrinter
    44.        End If
    45.     Next
    46. End If
    47.  
    48. ' Copy user input from the dialog box to the properties of the selected printer.
    49. Printer.Copies = printDlg.Copies
    50. Printer.Orientation = printDlg.Orientation
    51. Printer.ColorMode = printDlg.ColorMode
    52. Printer.Duplex = printDlg.Duplex
    53. Printer.PaperBin = printDlg.PaperBin
    54. Printer.PaperSize = printDlg.PaperSize
    55. Printer.PrintQuality = printDlg.PrintQuality
    56.  
    57. ' Display the results in the immediate (Debug) window.
    58. ' NOTE: Supported values for PaperBin and Size are printer specific. Some
    59. ' common defaults are defined in the Win32 SDK in MSDN and in Visual Basic.
    60. ' Print quality is the number of dots per inch.
    61. With Printer
    62.     Debug.Print .DeviceName
    63.     If .Orientation = 1 Then
    64.         strsetting = "Portrait. "
    65.     Else
    66.         strsetting = "Landscape. "
    67.     End If
    68.     Debug.Print "Copies = " & .Copies, "Orientation = " & _
    69.        strsetting
    70.     If .ColorMode = 1 Then
    71.         strsetting = "Black and White. "
    72.     Else
    73.         strsetting = "Color. "
    74.     End If
    75.     Debug.Print "ColorMode = " & strsetting
    76.     If .Duplex = 1 Then
    77.         strsetting = "None. "
    78.     ElseIf .Duplex = 2 Then
    79.         strsetting = "Horizontal/Long Edge. "
    80.     ElseIf .Duplex = 3 Then
    81.         strsetting = "Vertical/Short Edge. "
    82.     Else
    83.         strsetting = "Unknown. "
    84.     End If
    85.     Debug.Print "Duplex = " & strsetting
    86.     Debug.Print "PaperBin = " & .PaperBin
    87.     Debug.Print "PaperSize = " & .PaperSize
    88.     Debug.Print "PrintQuality = " & .PrintQuality
    89.     If (printDlg.Flags And VBPrinterConstants.cdlPDPrintToFile) = _
    90.        VBPrinterConstants.cdlPDPrintToFile Then
    91.          Debug.Print "Print to File Selected"
    92.     Else
    93.          Debug.Print "Print to File Not Selected"
    94.     End If
    95.     Debug.Print "hDC = " & printDlg.hDC
    96. End With
    97. rtb.SelPrint printDlg.hDC
    98. Exit Sub
    99. '**Cancel:
    100. '**If Err.Number = 32755 Then
    101. '**    Debug.Print "Cancel Selected"
    102. '**Else
    103. '**    Debug.Print "A nonCancel Error Occured - "; Err.Number
    104. '**End If

    However, this only prints if there is a textbox on the form. I have a listbox on my for and the listbox does not have a method called SelPrint(). Anyone have any suggestions?

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Printing Problems

    You cannot print just a listbox. You can however print a form that it's on using

    VB Code:
    1. PrintForm Form1

    in the dialog instead of printing the RTB.

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Printing Problems

    Quote Originally Posted by dglienna
    You cannot print just a listbox.
    You can print the contents of a listbox easily enough.
    VB Code:
    1. Dim lngIndex As Long
    2.    
    3.     For lngIndex = 0 To List1.ListCount - 1
    4.         Printer.Print List1.List(lngIndex);        
    5.     Next
    6.    
    7.     Printer.EndDoc

  9. #9
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Printing Problems

    I meant the actual listbox, not the items IN the listbox

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Printing Problems

    Hack rocks!

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Printing Problems

    You have to use Hacks method since if you have items in your listbox that are wider then the displayable width of the listbox, they would be chopped off and not printed..
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Printing Problems

    Thanks guys, it works

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: [RESOLVED] Printing Problems

    One quick question though: How can I change the font size? When it prints out it prints a little smaller than I would like for it to. I already tried changing the font size on the listbox property itself but it was not reflected when it was printed.

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Printing Problems

    Change the .Fontsize property of the Printer object.
    VB Code:
    1. Printer.ForeColor = vbRed
    2. Printer.Font = "Times New Roman"
    3. Printer.FontSize = 16
    4. Printer.FontItalic = True
    5. Printer.FontUnderline = True
    6. Printer.Print "This is in Red"
    7. Printer.Print
    8. Printer.Font = "Arial"
    9. Printer.FontSize = 12
    10. Printer.FontBold = True
    11. Printer.Forecolor = vbGreen
    12. Printer.Print "This is Green Arial font"
    13. Printer.EndDoc
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  15. #15
    Lively Member
    Join Date
    Jul 2001
    Posts
    95

    Re: [RESOLVED] Printing Problems

    Fantastic code dude. Thanks for you help.

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