|(Declarations)||Declarations||Declarations and private variables for the modVB_Printer module.|
|PrinterListToArray||Procedure||Populate a passed array with a list of the current printer devices on the system.|
|PrinterListToControl||Procedure||Populate a passed list box or combo box with a list of the current printer devices on the system. If you pass anything other than a list box or a combo box to this procedure, it simply exits.|
|PrinterSetDefault||Procedure||Set the application's default printer to the selected device. The strDeviceName is the name of the printer as it is known on your system. You can loop through the Printers collection to obtain a list of the valid printer DeviceNames on your system.|
|PrintRTFControl||Procedure||Print the contents of a RichTextBox. The RichTextBox control includes a method, SelPrint, to print the contents of the control. This method is of limited value because it does not let you print custom headers and footers. The PrintRTFControl procedure is designed specifically to allow the printing of custom headers and footers. This procedure requires a reference to "Microsoft Rich Textbox Control" in order to compile. This reference is automatically added when you insert an RTF control onto a form.|
' Example of the modVB_Printer module for Visual Basic 6 ' ' To use this example: ' 1. Create a new form ' 2. Create a command button called 'cmdTest' ' 3. Create a list box called 'lstPrinters' ' 4. Create a combo box called 'cboPrinters' ' 5. Create a Rich Text control called 'rtfTest' ' 6. Paste the entire contents of this module into the new form's module Private Sub cmdTest_Click() Static astrPrinters() As String Dim intCounter As Integer ' Example of PrinterListToArray PrinterListToArray astrPrinters ' print the list to the Immediate Window to verify that the array was populated For intCounter = 0 To UBound(astrPrinters) Debug.Print astrPrinters(intCounter) Next intCounter ' Example of PrinterListToControl ' Load the list of printers into a list box and a combo box PrinterListToControl lstPrinters PrinterListToControl cboPrinters ' Example of PrinterSetDefault ' Take the first printer in the list and make it the default printer ' Uncomment the following line of code to change the default printer ' PrinterSetDefault lstPrinters.List(0) Printer.Print lstPrinters.List(0) Printer.EndDoc ' Example of PrintRTFControl PrintRTFControl rtfTest, 1440, "PrintRTFControl Example", "", Me.Font End Sub Private Sub Form_Load() Dim strCopy As String Dim intCounter As Integer ' Generate some RTF text With rtfTest .Text = "" .SelBold = True .SelText = "Now " .SelBold = False .SelText = "is the " .SelItalic = True .SelText = "time " .SelItalic = False .SelText = "for all good men to come to the aid of their country. " .SelStart = 0 .SelLength = Len(.Text) strCopy = .SelRTF .SelStart = .SelLength For intCounter = 1 To 10 .SelRTF = strCopy Next intCounter End With cmdTest.Caption = "Printer" End Sub
The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.
Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!
Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!
"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."
Van T. Dinh, Microsoft MVP