Lesson 39: Printing in VB6
Master the Printer object to create professional printed output from your VB6 applications
Key Takeaway
The Printer object in VB6 provides powerful capabilities to send output directly to printers, allowing you to create professional documents, reports, and printed forms from your applications.
Welcome to Lesson 39 of our Visual Basic 6 Tutorial! In this lesson, you'll learn how to use the Printer object to send output directly to printers, format your printed documents, and create professional printed materials from your VB6 applications.
39.1 Understanding the Printer Object
VB6 provides a built-in Printer object that allows your applications to send output directly to printers. This object has several key methods and properties:
Print Method
Sends text to the printer, similar to how Print works for forms
NewPage
Starts a new page in the current print job
EndDoc
Sends the entire document to the printer
VB6 Code
Create output using Printer object
Print Spool
Document is queued for printing
Printer
Physical document is printed
Basic Printing Example
The simplest way to print from VB6 is to use the Printer object with the EndDoc method:
Private Sub Form_Load()
Printer.Print "Welcome to Visual Basic"
Printer.EndDoc
End Sub
Important
Always include Printer.EndDoc to actually send your document to the printer. Without it, your output will only be sent to the print spooler when the application terminates.
Printing Variables and Calculations
You can print variables and calculated values just like you would display them on a form:
Private Sub Command1_Click()
Dim x, y As String, z As Variant
x = InputBox("Enter the first Number")
y = InputBox("Enter the second Number")
z = Val(x) + Val(y)
Printer.Print "The answer is " & z
Printer.EndDoc
End Sub
Printing Text File Contents
You can easily print the contents of a text file or text box:
Private Sub CmdPrint_Click()
Printer.Print Text1.Text
Printer.EndDoc
End Sub
39.2 Formatting Printed Output
The Printer object provides several properties to format your printed output:
Font Properties
FontName, FontSize, FontBold, FontItalic, and FontUnderline allow you to control text appearance
Positioning
CurrentX and CurrentY properties control where the next output will appear
Page Management
NewPage method starts a new page, Page property tracks current page number
Text Formatting
ScaleWidth and ScaleHeight properties help with positioning elements
Formatting Example
This example demonstrates how to format printed text:
Private Sub CmdPrintFormatted_Click()
' Set font properties
Printer.FontName = "Verdana"
Printer.FontSize = 16
Printer.FontBold = True
Printer.FontItalic = True
Printer.FontUnderline = True
' Print centered title
Printer.CurrentX = (Printer.ScaleWidth - Printer.TextWidth("Report Title")) / 2
Printer.Print "Report Title"
' Reset formatting for body
Printer.FontBold = False
Printer.FontItalic = False
Printer.FontUnderline = False
Printer.FontSize = 10
' Print content
Printer.Print "This is a formatted report generated from VB6"
Printer.Print "Printed on: " & Format(Date, "Long Date")
' Add page number
Printer.CurrentY = Printer.ScaleHeight - 500
Printer.Print "Page " & Printer.Page
Printer.EndDoc
End Sub
Preview of Formatted Output
Report Title
This is a formatted report generated from VB6
Printed on: June 15, 2023
Printing Multiplication Table
This example uses nested loops to print a multiplication table:
Private Sub Command1_Click()
Dim i, j As Integer
For i = 2 To 9
For j = 2 To 9
Printer.Print i & "x" & j & " =" & i * j
Next j
Printer.Print ' Print blank line
Next i
Printer.EndDoc
End Sub
Lesson Summary
In this lesson, you've learned how to use the Printer object to create printed output from your VB6 applications:
Printer Object Basics
Using the Print method and EndDoc to send output to printers
Formatting Techniques
Controlling font properties, positioning, and page management
Practical Examples
Printing variables, calculations, text files, and formatted reports
Advanced Techniques
Using loops to generate complex printed output like tables
Pro Tip
For more complex printing needs, consider using the Printer object in combination with the PrintForm method to capture the current form state, or third-party reporting tools for advanced report generation.
Next Lesson
Continue your VB6 journey with Lesson 40: Report Creation where you'll learn to create professional database reports.
Related Resources

Visual Basic 6 Made Easy
The comprehensive guide to mastering VB6 development, including printing and reporting techniques.
What You'll Learn:
- Printer object fundamentals
- Formatting printed output
- Advanced printing techniques
- Database report generation
- Practical printing examples

Visual Basic 2022 Made Easy
The modern guide to VB.NET programming with Visual Studio 2022. Master modern printing and reporting techniques.
What You'll Learn:
- Modern printing techniques
- PrintDocument class
- Print preview functionality
- Crystal Reports integration
- PDF generation