473,322 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Multiple page printing with nested loops

it0ny
4
Hi guys,
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
  1. Public Class BRPDD 'Balance Report PrintingDocument Data
  2.  
  3.         Public totalReceiptsNum As Integer
  4.         Public totalLicFee As Double
  5.         Public totalClerk As Double
  6.         Public totalTotalFees As Double
  7.         Public totalCash As Double
  8.         Public totalCheck As Double
  9.         Public totalChange As Double
  10.         Public ReceiptTotalFees As Double
  11.         Public FinalMark As String
  12.         Public DepositRS As DAO.Recordset
  13.         Public ReceiptRS As DAO.Recordset
  14.  
  15.         Public Sub New()
  16.             ResetData()
  17.         End Sub
  18.  
  19.         Public Sub ResetData()
  20.             totalReceiptsNum = 0
  21.             totalLicFee = 0D
  22.             totalClerk = 0D
  23.             totalTotalFees = 0D
  24.             totalCash = 0D
  25.             totalCheck = 0D
  26.             totalChange = 0D
  27.             ReceiptTotalFees = 0D
  28.             FinalMark = ""
  29.             DepositRS = Nothing
  30.             ReceiptRS = Nothing
  31.         End Sub
  32.     End Class
  33.  
I made the class so that the current iteration of the receipts is not lost when the PrintPage handler sub is called again by
Expand|Select|Wrap|Line Numbers
  1. e.HasMorePages = True
So what I did is, I have a a form variable that is an instance of the class above, it is then initiated in the BeginPrint handler (DB class is a wrapper class to make easy query, I have tested this before and works fine, so the problem is not there):
Expand|Select|Wrap|Line Numbers
  1. Me.BalanceReport = New DBM.BRPDD
  2.         Dim dbobj As DBM.DB = New DBM.DB()
  3.  
  4.  
  5.         dbobj.openConnection()
  6.         dbobj.query("SELECT Deposits.* FROM Deposits WHERE DepositID=" & DepositIDString)
  7.         Me.BalanceReport.DepositRS = dbobj.Rs.Clone()
  8.  
  9.         dbobj.query("SELECT Receipts.* FROM Receipts WHERE DepositID=" & DepositIDString)
  10.         Me.BalanceReport.ReceiptRS = dbobj.Rs.Clone()
  11.  
  12.         Debug.Print("Report printing: initializing RSs.")
  13.         Debug.Print(Me.BalanceReport.totalCash.ToString())
  14.         Debug.Print(Me.BalanceReport.DepositRS.Fields.Count.ToString())
  15.         Debug.Print(Me.BalanceReport.ReceiptRS.Fields.Count.ToString())
  16.  
  17.         dbobj.closeConnections()
  18.         dbobj = Nothing
  19.  
The debug prints in that precedure they do return the right values. But when I go and put the same debug prints in the PrintPage says that the DepositRS and ReceiptsRS are "Object invalid or no longer set."

This is my PrintPage procedure:
Expand|Select|Wrap|Line Numbers
  1. Private Sub docuemt_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
  2. Handles ReportPrintDocument.PrintPage        
  3.     Me.PrintSettings = New PrintingDocData(e)
  4.     Me.PrintSettings.LeftMargin = e.MarginBounds.Left - 50
  5.     Debug.Print("Report printing: inside sub.")
  6.     Debug.Print(Me.BalanceReport.totalCash.ToString())
  7.     Debug.Print(Me.BalanceReport.DepositRS.Fields.Count.ToString())
  8.     Debug.Print(Me.BalanceReport.ReceiptRS.Fields.Count.ToString())
  9.  
  10.  
  11.     Dim dbobj As DBM.DB = New DBM.DB()
  12.     dbobj.openConnection()
  13.  
  14.     ' change paper orientation
  15.     ReportPrintDocument.DefaultPageSettings.Landscape = True
  16.  
  17.     '' Printout header
  18.  
  19.     '' loop through the receipts
  20.     Do Until BalanceReport.ReceiptRS.EOF
  21.         dbobj.query("SELECT LicenseFees.* FROM LicenseFees WHERE ReceiptID=" _
  22.                      & Me.BalanceReport.ReceiptRS.Fields("ReceiptID").Value.ToString())
  23.         Debug.Print("Report printing: selecting the licensefees.")
  24.         Do Until dbobj.Rs.EOF
  25.             '' printout the licenses that are in the receipt which takes only
  26.             '' 1 line of space.
  27.  
  28.             'If more lines exist, print another page.
  29.             If Me.PrintSettings.CurHeight >= Me.PrintSettings.PageHeight Then
  30.                 e.HasMorePages = True
  31.                 Debug.Print("trying to add a second page in line 458.")
  32.                 Me.PrintSettings.CurPage += 1
  33.                 Exit Sub
  34.  
  35.             Else
  36.                 e.HasMorePages = False
  37.             End If
  38.         Loop
  39.         Debug.Print("Report printing: printing receipts totals.")
  40.  
  41.         'print the totals of current receipt
  42.  
  43.         Debug.Print("Report printing: updating data variables.")
  44.         'Add the values to the totals
  45.         Me.BalanceReport.totalClerk += Double.Parse(Me.BalanceReport.ReceiptRS.Fields("ClerkFees").Value.ToString())
  46.         Me.BalanceReport.totalTotalFees += Double.Parse(Me.BalanceReport.ReceiptRS.Fields("Total").Value.ToString())
  47.         Me.BalanceReport.totalReceiptsNum += 1
  48.         'reset the current fee to 
  49.         Me.BalanceReport.ReceiptTotalFees = 0D
  50.         'move to the next record
  51.         Me.BalanceReport.ReceiptRS.MoveNext()
  52.     Loop
  53.  
  54.     ' print totals deposit's totals
  55.  
  56.     dbobj.closeConnections()
  57.     dbobj = Nothing
  58. End Sub
  59.  
  60.  
The error only happens with the DepositRS and ReceiptRS properties of the class, the other data in BalanceReport I can access it. A curious think is that BalanceReport is declared as Private on the form class, and when i change it to static or public it gives me an error saying "Error 1 'BalanceReport' cannot expose type 'DBM.BRPDD' outside the project through class 'DepositViewForm'."

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.
May 4 '09 #1
0 2802

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: chad | last post by:
I am writing a program to do some reliability calculations that require several nested for-loops. However, I believe that as the models become more complex, the number of required for-loops will...
11
by: Alban Hertroys | last post by:
Oh no! It's me and transactions again :) I'm not really sure whether this is a limitation of psycopg or postgresql. When I use multiple cursors in a transaction, the records inserted at the...
46
by: Neptune | last post by:
Hello. I am working my way through Zhang's "Teach yourself C in 24 hrs (2e)" (Sam's series), and for nested loops, he writes (p116) "It's often necessary to create a loop even when you are...
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
33
by: Geometer | last post by:
Hello, and good whatever daytime is at your place.. please can somebody tell me, what the standard behavior of strtok shall be, if it encounters two or more consecutive delimiters like in...
9
by: Gregory Petrosyan | last post by:
I often make helper functions nested, like this: def f(): def helper(): ... ... is it a good practice or not? What about performance of such constructs?
4
by: Matt Ratliff | last post by:
Hello, I would appreciate any assistance you have with the following problem: I have (as an example) an array of values as follows: arrayvalues=new Array("0001","0003","0005") where each is the...
8
by: Nathan Sokalski | last post by:
I have several nested For loops, as follows: For a As Integer = 0 To 255 For b As Integer = 0 To 255 For c As Integer = 0 To 255 If <Boolean ExpressionThen <My CodeElse Exit For Next If Not...
5
by: TP | last post by:
Hi everybody, Several means to escape a nested loop are given here: http://stackoverflow.com/questions/189645/how-to-break-out-of-multiple-loops-in-python According to this page, the best...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.