Search Tools Links Login

Print Layout

This piece of code loops through the controls on a form and sends the contents to the default printer in a layout similar to the screen. Therefore your forms contents are printed in the same positions as they are on screen. I use this to print out a simple record report on the db application I am working on. Works with labels, text boxes and list boxes etc.

Original Author: ronniec23


Sub Print_rec()
On Error GoTo print_err
With Printer
  .Orientation = 1 '1 = portrait, 2 = landscape
  .CurrentX = 3000 ' move text over and down for title
  .CurrentY = 1440
  .FontBold = True
  .FontSize = 12
  Printer.Print "Record Details"
  .FontSize = 9 'Change back font size
  .FontBold = False 'Change back to none bold font
'This section loops through the controls on the screen and prints the contents of the control.
' I used the tag property to filter controls as there was some controls on the screen I didnt want printing (buttons, check boxes etc.)
For Each Control In Me.Controls
  If Control.Tag = "prt" Then
  .CurrentX = Control.Left + 250 ' sets the position for printing (+ 250 move's it in about 1cm from side of sheet)
  .CurrentY = Control.Top + 2400 ' + 2400 allows space for title
  If Control.Name Like "lbl*" Then
    Printer.Print Control.Caption & ":"  'print label captions and a ":"
  Printer.Print Control.Text ' prints contents of text box
  End If
  End If
Next Control
End With
MsgBox "Printed!"
Exit Sub
  MsgBox "Error in printing tender details."
  Exit Sub
End Sub

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 83 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.