trbbhm
asked on
How to Print Multiple Pages using PrintDocument
I have a program in which I want to print a postcard for each record in a datareader control. Currently I am calling the PrintDocument.Print command after each record is read. What I would like to do is to create a new "page" for each record and then only call the Print command once. I've included some code below:
....while reader reads....
Dim custcitystatezip As String
Dim prn As New PrintDocument
custcitystatezip = StrConv(Trim(Reader("primc ity")), VbStrConv.ProperCase)
custcitystatezip += ", " & Trim(Reader("primstate"))
custcitystatezip += " " & Trim(Reader("primzipfirst5 "))
PostcardAddress = custname & vbCrLf & custaddr & vbCrLf & custcitystatezip & vbCrLf & vbCrLf & vbCrLf & Reader("repairnum")
AddHandler prn.PrintPage, AddressOf Me.PrintPageHandler
Dim ps As System.Drawing.Printing.Pa perSource
For Each ps In prn.PrinterSettings.PaperS ources
If ps.SourceName = "Tray2" Then
prn.DefaultPageSettings.Pa perSource = ps
Exit For
End If
Next
prn.DefaultPageSettings.La ndscape = True
prn.Print()
RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHandler
....while reader reads....
Dim custcitystatezip As String
Dim prn As New PrintDocument
custcitystatezip = StrConv(Trim(Reader("primc
custcitystatezip += ", " & Trim(Reader("primstate"))
custcitystatezip += " " & Trim(Reader("primzipfirst5
PostcardAddress = custname & vbCrLf & custaddr & vbCrLf & custcitystatezip & vbCrLf & vbCrLf & vbCrLf & Reader("repairnum")
AddHandler prn.PrintPage, AddressOf Me.PrintPageHandler
Dim ps As System.Drawing.Printing.Pa
For Each ps In prn.PrinterSettings.PaperS
If ps.SourceName = "Tray2" Then
prn.DefaultPageSettings.Pa
Exit For
End If
Next
prn.DefaultPageSettings.La
prn.Print()
RemoveHandler prn.PrintPage, AddressOf Me.PrintPageHandler
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Computer101
EE Admin