VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Print Layout

by ronniec23 (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 5.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

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.

Rate Print Layout

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 ":"
  Else
  Printer.Print Control.Text ' prints contents of text box
  End If
  End If
Next Control
.EndDoc
End With
MsgBox "Printed!"
Exit Sub
print_err:
  MsgBox "Error in printing tender details."
  Exit Sub
End Sub

Download this snippet    Add to My Saved Code

Print Layout Comments

No comments have been posted about Print Layout. Why not be the first to post a comment about Print Layout.

Post your comment

Subject:
Message:
0/1000 characters