943,929 Members | Top Members by Rank

Ad:
Nov 19th, 2008
0

Printing information

Expand Post »
Hi,

im doing a program in VB and i want to print my clients information.

But i dont want to print a printscreen of the form, i want to print a list of all my clients on a page design by me, i know that is possible to design the print page in acess but i dont know how to do it on VB and how to select by code, the number of clients that i want printed on the list.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
quenestil is offline Offline
3 posts
since Nov 2008
Nov 19th, 2008
0

Re: Printing information

Click to Expand / Collapse  Quote originally posted by quenestil ...
Hi,

im doing a program in VB and i want to print my clients information.

But i dont want to print a printscreen of the form, i want to print a list of all my clients on a page design by me, i know that is possible to design the print page in acess but i dont know how to do it on VB and how to select by code, the number of clients that i want printed on the list.
well, there are different ways to use the printer; i don't really remember them off hand. the standard way isn't as easy as one would like, but it'll work...

to test this, and save on paper; i suggest that you create a picture box and print to it using the same method shown here; only difference is the EndDoc; don't use that with a picturebox

anyway, on to the code...

now, i'm assuming you have some kind of client list; so i thought i'd make one up just for a visual...

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Type myCLIENTS
  2. stName as String * 32
  3. stHomePhone as string * 10
  4. stWhatever as string * 32
  5. End Type
  6.  
  7. Private Clients() as myCLIENTS
  8. Private iPage as Integer

I happen to like Types, you might notice this if you look at any of my other posts...
anyway, in my sample that i wrote and tested with, i hard coded the variables in a sub i called 'SET_CLIENTS'

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub SET_CLIENTS()
  2. ReDim Clients(1 To 10)
  3. Clients(1).stName = "Joe Bob"
  4. Clients(1).stHomephone = "1111111111"
  5. Clients(1).stWhatever = "nice number"
  6. Clients(2).stName = "Jill Bob"
  7. Clients(2).stHomephone = "2222222222"
  8. Clients(2).stWhatever = "nice number"
  9. Clients(3).stName = "Betty Bob"
  10. Clients(3).stHomephone = "3333333333"
  11. Clients(3).stWhatever = "nice number"
  12. Clients(4).stName = "Billy Bob"
  13. Clients(4).stHomephone = "4444444444"
  14. Clients(4).stWhatever = "nice number"
  15. Clients(5).stName = "Brandy Bob"
  16. Clients(5).stHomephone = "5555555555"
  17. Clients(5).stWhatever = "nice number"
  18. Clients(6).stName = "Robby Bob"
  19. Clients(6).stHomephone = "6666666666"
  20. Clients(6).stWhatever = "nice number"
  21. Clients(7).stName = "Ricky Bob"
  22. Clients(7).stHomephone = "7777777777"
  23. Clients(7).stWhatever = "nice number"
  24. Clients(8).stName = "Joe Bob Sr"
  25. Clients(8).stHomephone = "8888888888"
  26. Clients(8).stWhatever = "nice number"
  27. Clients(9).stName = "Joe Bob Jr"
  28. Clients(9).stHomephone = "9999999999"
  29. Clients(9).stWhatever = "nice number"
  30. Clients(10).stName = "Bobby Sue"
  31. Clients(10).stHomephone = "1234567890"
  32. Clients(10).stWhatever = "nice number"
  33. End Sub

yes, very creative i know... but I'm just trying to show how this works...
now, to print the page header... only need to do this once if you only have 1 page, but... you might have more...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub PRINT_HEADER()
  2. iPage = iPage + 1
  3. Dim sPrinterY As Single
  4. Dim sPrinterY2 As Single
  5. Printer.ScaleMode = vbInches
  6. Printer.CurrentX = 0.25 'set printer to 0.25 inches in on the page
  7. Printer.FontSize = 18
  8. Printer.FontName = "Arial"
  9. sPrinterY = Printer.CurrentY
  10. Printer.Print "Client List"
  11. sPrinterY2 = Printer.CurrentY 'yeah, this is really sloppy;
  12. 'but it's just to get the different
  13. 'height of font size 18
  14. Printer.CurrentY = sPrinterY
  15. Printer.FontSize = 10
  16. Printer.CurrentX = 7
  17. Printer.Print "Page " & Trim$(Str$(iPage))
  18. Printer.CurrentY = sPrinterY2
  19. Printer.FontSize = 10
  20. Printer.CurrentX = 0.25
  21. Printer.FontUnderline = True
  22. stestY = Printer.CurrentY
  23. Printer.Print "Client Name"
  24. Printer.CurrentY = stestY
  25. Printer.CurrentX = 1.75
  26. Printer.Print "Phone"
  27. Printer.CurrentY = stestY
  28. Printer.CurrentX = 2.75
  29. Printer.Print "whatever"
  30. Printer.FontUnderline = False
  31. End Sub

this is where iPage comes into play, just allows you to write what page it is on the header. unfortunately since i'm not sure how many pages there will be off hand, this example will not print page 1 of 10 or whatever page count there is... (you could by printing it twice, killing the document and saving the current value of iPage in iPageCount, then printing "Page " & trim$(str$(iPage)) & " of " & $trim(str$(iPageCount))

anyway, that's the header.. kind of annoying to print this way, and yes i'm aware that this isn't the most opitimized or even close to it (neccessarily) way to do this.. but i haven't used the printer object in a good 10 years...

now for printing the list...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub PRINT_LIST()
  2. Dim sPrinterY As Single
  3. For x = 1 To 10
  4. sPrinterY = Printer.CurrentY
  5. If sPrinterY >= Printer.Height Then
  6. Printer.NewPage
  7. PRINT_HEADER
  8. End If
  9. Printer.CurrentX = 0.25
  10. Printer.Print Trim$(Clients(x).stName)
  11. Printer.CurrentY = sPrinterY
  12. Printer.CurrentX = 1.75
  13. Printer.Print Trim$(Format(Val(Clients(x).stHomephone), "(###)###-####"))
  14. Printer.CurrentY = sPrinterY
  15. Printer.CurrentX = 2.75
  16. Printer.Print Trim$(Clients(x).stWhatever)
  17. Next x
  18. Printer.EndDoc
  19. iPage = 0
  20. End Sub

and finally how i called everything for testing (this was all done in a single form by the way)
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Form_Load()
  2. Printer.ScaleMode = vbInches
  3. SET_CLIENTS
  4. PRINT_HEADER
  5. PRINT_LIST
  6. End Sub

if you want to test your document out before printing it, use a picture box. replace 'Printer.' with the name of your picturebox. (ie: picPage.print). endDoc won't apply to print page and new page won't do anthing either, but it's a good way to get a feel for your document without printing anything / wasting ink / paper...
Reputation Points: 22
Solved Threads: 3
Light Poster
kain_mcbride is offline Offline
25 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: MScomm send problem
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Run-Time Error '-2147217842(80040e4e)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC