Trouble printing multiple pages..

A

Andrew

Trying to print out a parts list on multiple pages and not sure exactly how
to do this. This is my code below as an attempt to do so.

'now going to load parts
'load connection
conn.ConnectionString = mdlMain.strConnString
conn.Open()

Dim sql As String = "select * from part_tbl"
e.PageSettings.Margins = New System.Drawing.Printing.Margins(50, 50,
50, 50)
Dim g As Graphics = e.Graphics
Dim rCount As Long = 0
Dim iPages As Long = 1
Dim iStartPoint As Long = 220
iGCount = 0

'Try

command = New System.Data.OleDb.OleDbCommand(sql, conn)
datareader = command.ExecuteReader


Do While datareader.Read
iGCount += 1
If MDIParent.iLastRecord > iGCount Then
If Not datareader.Item("part_itemnum") Is DBNull.Value Then
DrowRecText(e, 50, iStartPoint, 230, 30, 12, False,
fAlign.Left, Color.Black, Color.Blue, _
datareader.Item("part_itemnum"), False)
End If
End If
iStartPoint += 24
rCount += 1
If rCount = 30 Then
MDIParent.iLastRecord += rCount
e.HasMorePages = True
rCount = 0
Exit Sub
Else
e.HasMorePages = False
End If
System.Windows.Forms.Application.DoEvents()
Loop

g.Dispose()

'Catch ex As Exception
'Call mdlMain.LogError(ex.Message, sql)
'End Try

'-----------------------------------------------------------------------------------------



e.HasMorePages = False

conn.Close()

I am not sure how to print the rest of the data to the second page and so on..
 
A

Armin Zingler

Andrew said:
Trying to print out a parts list on multiple pages and not sure
exactly how to do this. This is my code below as an attempt to do so.


You must select the data before you start printing. Make the data available
to the printpage event. Also keep the data that you need to preserve from
page to page outside the event handler, otherwise it gets lost - unless you
use Static local variables (that I would not recommend because they can't be
initialized a second time).
System.Windows.Forms.Application.DoEvents()

(Please, no DoEvents anymore. It's risky. If you want to do 2 different
things at a time, use two threads instad. IMO only.)


Amin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top