|
-
Oct 24th, 2005, 10:10 AM
#1
Thread Starter
Addicted Member
[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.
-
Oct 24th, 2005, 11:37 AM
#2
Re: Printing Problems
I've never heard of that reference before, what is it? Are you sure you need it?
-
Oct 24th, 2005, 11:46 AM
#3
Re: Printing Problems
 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?
-
Oct 24th, 2005, 12:19 PM
#4
Thread Starter
Addicted Member
Re: Printing Problems
Ok here's the code:
VB Code:
Dim printDlg As PrinterDlg
Set printDlg = New PrinterDlg
' Set the starting information for the dialog box based on the current
' printer settings.
printDlg.PrinterName = Printer.DeviceName
printDlg.DriverName = Printer.DriverName
printDlg.Port = Printer.Port
' Set the default PaperBin so that a valid value is returned even
' in the Cancel case.
printDlg.PaperBin = Printer.PaperBin
' Set the flags for the PrinterDlg object using the same flags as in the
' common dialog control. The structure starts with VBPrinterConstants.
printDlg.Flags = VBPrinterConstants.cdlPDNoSelection _
Or VBPrinterConstants.cdlPDNoPageNums _
Or VBPrinterConstants.cdlPDReturnDC
Printer.TrackDefault = False
' When CancelError is set to True the ShowPrinterDlg will return error
' 32755. You can handle the error to know when the Cancel button was
' clicked. Enable this by uncommenting the lines prefixed with "'**".
'**printDlg.CancelError = True
' Add error handling for Cancel.
'**On Error GoTo Cancel
If Not printDlg.ShowPrinter(Me.hWnd) Then
Debug.Print "Cancel Selected"
Exit Sub
End If
'Turn off Error Handling for Cancel.
'**On Error GoTo 0
Dim NewPrinterName As String
Dim objPrinter As Printer
Dim strsetting As String
' Locate the printer that the user selected in the Printers collection.
NewPrinterName = UCase$(printDlg.PrinterName)
If Printer.DeviceName <> NewPrinterName Then
For Each objPrinter In Printers
If UCase$(objPrinter.DeviceName) = NewPrinterName Then
Set Printer = objPrinter
End If
Next
End If
' Copy user input from the dialog box to the properties of the selected printer.
Printer.Copies = printDlg.Copies
Printer.Orientation = printDlg.Orientation
Printer.ColorMode = printDlg.ColorMode
Printer.Duplex = printDlg.Duplex
Printer.PaperBin = printDlg.PaperBin
Printer.PaperSize = printDlg.PaperSize
Printer.PrintQuality = printDlg.PrintQuality
' Display the results in the immediate (Debug) window.
' NOTE: Supported values for PaperBin and Size are printer specific. Some
' common defaults are defined in the Win32 SDK in MSDN and in Visual Basic.
' Print quality is the number of dots per inch.
With Printer
Debug.Print .DeviceName
If .Orientation = 1 Then
strsetting = "Portrait. "
Else
strsetting = "Landscape. "
End If
Debug.Print "Copies = " & .Copies, "Orientation = " & _
strsetting
If .ColorMode = 1 Then
strsetting = "Black and White. "
Else
strsetting = "Color. "
End If
Debug.Print "ColorMode = " & strsetting
If .Duplex = 1 Then
strsetting = "None. "
ElseIf .Duplex = 2 Then
strsetting = "Horizontal/Long Edge. "
ElseIf .Duplex = 3 Then
strsetting = "Vertical/Short Edge. "
Else
strsetting = "Unknown. "
End If
Debug.Print "Duplex = " & strsetting
Debug.Print "PaperBin = " & .PaperBin
Debug.Print "PaperSize = " & .PaperSize
Debug.Print "PrintQuality = " & .PrintQuality
If (printDlg.Flags And VBPrinterConstants.cdlPDPrintToFile) = _
VBPrinterConstants.cdlPDPrintToFile Then
Debug.Print "Print to File Selected"
Else
Debug.Print "Print to File Not Selected"
End If
Debug.Print "hDC = " & printDlg.hDC
End With
rtb.SelPrint printDlg.hDC
Exit Sub
'**Cancel:
'**If Err.Number = 32755 Then
'** Debug.Print "Cancel Selected"
'**Else
'** Debug.Print "A nonCancel Error Occured - "; Err.Number
'**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.
-
Oct 24th, 2005, 12:24 PM
#5
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.
-
Oct 31st, 2005, 01:32 PM
#6
Thread Starter
Addicted Member
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:
Dim printDlg As PrinterDlg
Set printDlg = New PrinterDlg
' Set the starting information for the dialog box based on the current
' printer settings.
printDlg.PrinterName = Printer.DeviceName
printDlg.DriverName = Printer.DriverName
printDlg.Port = Printer.Port
' Set the default PaperBin so that a valid value is returned even
' in the Cancel case.
printDlg.PaperBin = Printer.PaperBin
' Set the flags for the PrinterDlg object using the same flags as in the
' common dialog control. The structure starts with VBPrinterConstants.
printDlg.Flags = VBPrinterConstants.cdlPDNoSelection _
Or VBPrinterConstants.cdlPDNoPageNums _
Or VBPrinterConstants.cdlPDReturnDC
Printer.TrackDefault = False
' When CancelError is set to True the ShowPrinterDlg will return error
' 32755. You can handle the error to know when the Cancel button was
' clicked. Enable this by uncommenting the lines prefixed with "'**".
'**printDlg.CancelError = True
' Add error handling for Cancel.
'**On Error GoTo Cancel
If Not printDlg.ShowPrinter(Me.hWnd) Then
Debug.Print "Cancel Selected"
Exit Sub
End If
'Turn off Error Handling for Cancel.
'**On Error GoTo 0
Dim NewPrinterName As String
Dim objPrinter As Printer
Dim strsetting As String
' Locate the printer that the user selected in the Printers collection.
NewPrinterName = UCase$(printDlg.PrinterName)
If Printer.DeviceName <> NewPrinterName Then
For Each objPrinter In Printers
If UCase$(objPrinter.DeviceName) = NewPrinterName Then
Set Printer = objPrinter
End If
Next
End If
' Copy user input from the dialog box to the properties of the selected printer.
Printer.Copies = printDlg.Copies
Printer.Orientation = printDlg.Orientation
Printer.ColorMode = printDlg.ColorMode
Printer.Duplex = printDlg.Duplex
Printer.PaperBin = printDlg.PaperBin
Printer.PaperSize = printDlg.PaperSize
Printer.PrintQuality = printDlg.PrintQuality
' Display the results in the immediate (Debug) window.
' NOTE: Supported values for PaperBin and Size are printer specific. Some
' common defaults are defined in the Win32 SDK in MSDN and in Visual Basic.
' Print quality is the number of dots per inch.
With Printer
Debug.Print .DeviceName
If .Orientation = 1 Then
strsetting = "Portrait. "
Else
strsetting = "Landscape. "
End If
Debug.Print "Copies = " & .Copies, "Orientation = " & _
strsetting
If .ColorMode = 1 Then
strsetting = "Black and White. "
Else
strsetting = "Color. "
End If
Debug.Print "ColorMode = " & strsetting
If .Duplex = 1 Then
strsetting = "None. "
ElseIf .Duplex = 2 Then
strsetting = "Horizontal/Long Edge. "
ElseIf .Duplex = 3 Then
strsetting = "Vertical/Short Edge. "
Else
strsetting = "Unknown. "
End If
Debug.Print "Duplex = " & strsetting
Debug.Print "PaperBin = " & .PaperBin
Debug.Print "PaperSize = " & .PaperSize
Debug.Print "PrintQuality = " & .PrintQuality
If (printDlg.Flags And VBPrinterConstants.cdlPDPrintToFile) = _
VBPrinterConstants.cdlPDPrintToFile Then
Debug.Print "Print to File Selected"
Else
Debug.Print "Print to File Not Selected"
End If
Debug.Print "hDC = " & printDlg.hDC
End With
rtb.SelPrint printDlg.hDC
Exit Sub
'**Cancel:
'**If Err.Number = 32755 Then
'** Debug.Print "Cancel Selected"
'**Else
'** Debug.Print "A nonCancel Error Occured - "; Err.Number
'**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.
-
Oct 31st, 2005, 02:08 PM
#7
Re: Printing Problems
You cannot print just a listbox. You can however print a form that it's on using
in the dialog instead of printing the RTB.
-
Oct 31st, 2005, 02:16 PM
#8
Re: Printing Problems
 Originally Posted by dglienna
You cannot print just a listbox.
You can print the contents of a listbox easily enough.
VB Code:
Dim lngIndex As Long
For lngIndex = 0 To List1.ListCount - 1
Printer.Print List1.List(lngIndex);
Next
Printer.EndDoc
-
Oct 31st, 2005, 02:43 PM
#9
Re: Printing Problems
I meant the actual listbox, not the items IN the listbox
-
Oct 31st, 2005, 03:06 PM
#10
Thread Starter
Addicted Member
Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.
-
Oct 31st, 2005, 03:14 PM
#11
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Oct 31st, 2005, 03:49 PM
#12
Thread Starter
Addicted Member
Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.
-
Oct 31st, 2005, 04:17 PM
#13
Thread Starter
Addicted Member
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.
-
Oct 31st, 2005, 04:59 PM
#14
Re: [RESOLVED] Printing Problems
Change the .Fontsize property of the Printer object.
VB Code:
Printer.ForeColor = vbRed
Printer.Font = "Times New Roman"
Printer.FontSize = 16
Printer.FontItalic = True
Printer.FontUnderline = True
Printer.Print "This is in Red"
Printer.Print
Printer.Font = "Arial"
Printer.FontSize = 12
Printer.FontBold = True
Printer.Forecolor = vbGreen
Printer.Print "This is Green Arial font"
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Mar 20th, 2006, 04:58 AM
#15
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|