thanks I am fairly new to this forum so I hope I chose the right place to post this question.
I try to make my program printout a deposit's report. I created a class to store the printing printing data and the actual database data in a recordset.
the class looks like this:
Expand|Select|Wrap|Line Numbers
- Public Class BRPDD 'Balance Report PrintingDocument Data
- Public totalReceiptsNum As Integer
- Public totalLicFee As Double
- Public totalClerk As Double
- Public totalTotalFees As Double
- Public totalCash As Double
- Public totalCheck As Double
- Public totalChange As Double
- Public ReceiptTotalFees As Double
- Public FinalMark As String
- Public DepositRS As DAO.Recordset
- Public ReceiptRS As DAO.Recordset
- Public Sub New()
- ResetData()
- End Sub
- Public Sub ResetData()
- totalReceiptsNum = 0
- totalLicFee = 0D
- totalClerk = 0D
- totalTotalFees = 0D
- totalCash = 0D
- totalCheck = 0D
- totalChange = 0D
- ReceiptTotalFees = 0D
- FinalMark = ""
- DepositRS = Nothing
- ReceiptRS = Nothing
- End Sub
- End Class
Expand|Select|Wrap|Line Numbers
- e.HasMorePages = True
Expand|Select|Wrap|Line Numbers
- Me.BalanceReport = New DBM.BRPDD
- Dim dbobj As DBM.DB = New DBM.DB()
- dbobj.openConnection()
- dbobj.query("SELECT Deposits.* FROM Deposits WHERE DepositID=" & DepositIDString)
- Me.BalanceReport.DepositRS = dbobj.Rs.Clone()
- dbobj.query("SELECT Receipts.* FROM Receipts WHERE DepositID=" & DepositIDString)
- Me.BalanceReport.ReceiptRS = dbobj.Rs.Clone()
- Debug.Print("Report printing: initializing RSs.")
- Debug.Print(Me.BalanceReport.totalCash.ToString())
- Debug.Print(Me.BalanceReport.DepositRS.Fields.Count.ToString())
- Debug.Print(Me.BalanceReport.ReceiptRS.Fields.Count.ToString())
- dbobj.closeConnections()
- dbobj = Nothing
This is my PrintPage procedure:
Expand|Select|Wrap|Line Numbers
- Private Sub docuemt_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
- Handles ReportPrintDocument.PrintPage
- Me.PrintSettings = New PrintingDocData(e)
- Me.PrintSettings.LeftMargin = e.MarginBounds.Left - 50
- Debug.Print("Report printing: inside sub.")
- Debug.Print(Me.BalanceReport.totalCash.ToString())
- Debug.Print(Me.BalanceReport.DepositRS.Fields.Count.ToString())
- Debug.Print(Me.BalanceReport.ReceiptRS.Fields.Count.ToString())
- Dim dbobj As DBM.DB = New DBM.DB()
- dbobj.openConnection()
- ' change paper orientation
- ReportPrintDocument.DefaultPageSettings.Landscape = True
- '' Printout header
- '' loop through the receipts
- Do Until BalanceReport.ReceiptRS.EOF
- dbobj.query("SELECT LicenseFees.* FROM LicenseFees WHERE ReceiptID=" _
- & Me.BalanceReport.ReceiptRS.Fields("ReceiptID").Value.ToString())
- Debug.Print("Report printing: selecting the licensefees.")
- Do Until dbobj.Rs.EOF
- '' printout the licenses that are in the receipt which takes only
- '' 1 line of space.
- 'If more lines exist, print another page.
- If Me.PrintSettings.CurHeight >= Me.PrintSettings.PageHeight Then
- e.HasMorePages = True
- Debug.Print("trying to add a second page in line 458.")
- Me.PrintSettings.CurPage += 1
- Exit Sub
- Else
- e.HasMorePages = False
- End If
- Loop
- Debug.Print("Report printing: printing receipts totals.")
- 'print the totals of current receipt
- Debug.Print("Report printing: updating data variables.")
- 'Add the values to the totals
- Me.BalanceReport.totalClerk += Double.Parse(Me.BalanceReport.ReceiptRS.Fields("ClerkFees").Value.ToString())
- Me.BalanceReport.totalTotalFees += Double.Parse(Me.BalanceReport.ReceiptRS.Fields("Total").Value.ToString())
- Me.BalanceReport.totalReceiptsNum += 1
- 'reset the current fee to
- Me.BalanceReport.ReceiptTotalFees = 0D
- 'move to the next record
- Me.BalanceReport.ReceiptRS.MoveNext()
- Loop
- ' print totals deposit's totals
- dbobj.closeConnections()
- dbobj = Nothing
- End Sub
I am thinking maybe after the BeginPrint something de-references these recordsets.
I don't know if any of you have an idea why this is happening or if there is a better way to printout multiple pages.
BTW I know DAO is old school, but I am using it because this old bug was just put in my hands and the department needs a quick fix for this. DAO recordsets are used throughout the muilti-form program so it is overhead to make the change to ADO.NET. I am going to advise to change it after this bug is fix.
Sorry for the long post, but really thank you in advance.