Home General VB/VBA Print Form to Default Printer
20 | 05 | 2012
This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade

Print Form to Default Printer PDF Print E-mail
User Rating: / 0
PoorBest 
Tutorials
Written by Administrator   

It is possible to print a Form to the default printer. You can use the code below to do so.

Show/Hidden vbnet code

View source
Private Sub Command1_Click()
 
 
 
	'****************************************
 
	'*** Code from VisibleVisual.com ********
 
	'****************************************
 
 
 
	PrintFormFields Printer, Me, True
 
	Printer.EndDoc
 
 
 
	End Sub
 
 
 
 
 
	' Print the Labels and TextBoxes.
 
	Private Sub PrintFormFields(ptr As Object, frm As Form, draw_box As Boolean)
 
	Dim ctl As Control
 
	Dim wid As Single
 
	Dim hgt As Single
 
 
 
	For Each ctl In frm.Controls
 
	If TypeOf ctl Is Label Then
 
	PrintText ptr, frm, ctl, ctl.Caption, False
 
	ElseIf TypeOf ctl Is TextBox Then
 
	PrintText ptr, frm, ctl, ctl.Text, True
 
	End If
 
	Next ctl
 
 
 
	If draw_box Then
 
	wid = frm.ScaleX(frm.ScaleWidth, frm.ScaleMode, vbTwips)
 
	hgt = frm.ScaleY(frm.ScaleHeight, frm.ScaleMode, vbTwips)
 
	ptr.Line (0, 0)-Step(wid, hgt), , B
 
	End If
 
	End Sub
 
 
 
	' Print text where the control belongs.
 
	Private Sub PrintText(ptr As Object, frm As Form, ctl As Control, txt As String, draw_box As Boolean)
 
	Dim l As Single
 
	Dim t As Single
 
	Dim wid As Single
 
	Dim hgt As Single
 
 
 
	l = frm.ScaleX(ctl.Left, frm.ScaleMode, vbTwips)
 
	t = frm.ScaleY(ctl.Top, frm.ScaleMode, vbTwips)
 
	If draw_box Then
 
	ptr.CurrentX = l + _
 
	ScaleX(0.2 * ctl.Font.Size, vbPoints, vbTwips)
 
	ptr.CurrentY = t + _
 
	ScaleY(0.2 * ctl.Font.Size, vbPoints, vbTwips)
 
	Else
 
	ptr.CurrentX = l
 
	ptr.CurrentY = t
 
	End If
 
 
 
	' Select the printer font.
 
	ptr.Font.Name = ctl.Font.Name
 
	ptr.Font.Size = ctl.Font.Size
 
 
 
	ptr.Print txt
 
	If draw_box Then
 
	wid = frm.ScaleX(ctl.Width, frm.ScaleMode, vbTwips)
 
	hgt = frm.ScaleY(ctl.Height, frm.ScaleMode, vbTwips)
 
	ptr.Line (l, t)-Step(wid, hgt), , B
 
	End If
 
	End Sub

Attachments:
FileDescriptionFile sizeDownloads
Download this file (Print Form.zip)Print Form to Default PrinterPrint Form to Default Printer6 Kb217
 

Add comment


Security code
Refresh

This site has been updated and renewed. You have followed an old link.

Click here to go to the new site

http://www.visiblevisual.com/jupgrade