473,221 Members | 1,918 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,221 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 2784

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 online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.