My Assistant
![]() ![]() |
|
|
Mar 13 2012, 04:22 AM
Post
#1
|
|
|
UtterAccess VIP Posts: 1,603 From: Belgium |
Hi,
I have a report that has several subreports on it, which need to be summed for a grand total. (see also: older post regarding same problem) So, when the report is on more then 1 page long, and a subreport starts on the second page, the grand total is not correct. The first value from that subreport is added twice to the grand total. When the subreport is spread over the 2 pages, the grand total is calculated correct. And now for the really strange part: this only occurs in A2007. In A2010 the grand total is correct in both cases. (IMG:style_emoticons/default/iconfused.gif) For your information: the front end (mde) was created in A2007. Anyone got any idea what is happening and how to solve it (yeah, I know: upgrade to A2010 (IMG:style_emoticons/default/smirk.gif) ) |
|
|
|
Mar 13 2012, 10:49 AM
Post
#2
|
|
|
UtterAccess VIP Posts: 1,857 From: BC, Canada |
How are you accumulating the grand total?
Mike |
|
|
|
Mar 13 2012, 11:15 AM
Post
#3
|
|
|
UtterAccess VIP Posts: 1,603 From: Belgium |
Hi Mike,
Following code is used (= adaptation of code found here on UA): CODE Option Compare Database Option Explicit Dim dblTotaal As Double, dblBDTotaal As Double Dim dblBDRATotaal As Double, dblKPTotaal As Double Dim dblSBTotaal As Double, dblBTotaal As Double Dim dblWPTotaal As Double, dblWPRATotaal As Double Dim dblETotaal As Double Function fInitBD() 'set total to zero when opening rptRekenblad dblTotaal = 0 'set totals for bladdelen to zero when opening rsubBD dblBDTotaal = 0 dblBDRATotaal = 0 End Function Function fInitKP() 'set total for kookplaat to zero when opening rsubKP dblKPTotaal = 0 End Function Function fInitSB() 'set total for spoelbak to zero when opening rsubSB dblSBTotaal = 0 End Function Function fInitB() 'set total for bewerking to zero when opening rsubB dblBTotaal = 0 End Function Function fInitWP() 'set totals for wandplaten to zero when opening rsubWP dblWPTotaal = 0 dblWPRATotaal = 0 End Function Function fInitE() 'set total for extra bewerking to zero when opening rsubE dblETotaal = 0 End Function Function fCalcBD(R As Report) 'summing bladdelen Dim tmp As Double tmp = Nz(R!txtPBD, 0) dblBDTotaal = dblBDTotaal + tmp dblTotaal = dblTotaal + tmp fCalcBD = tmp End Function Function fCalcBDTotaal() 'put sum bladdelen in reportfooter fCalcBDTotaal = dblBDTotaal dblBDTotaal = 0 End Function Function fCalcRA(R As Report) 'summing randafwerkingen Dim tmp As Double tmp = Nz(R!txtPBDRA, 0) dblBDRATotaal = dblBDRATotaal + tmp dblTotaal = dblTotaal + tmp fCalcRA = dblBDRATotaal End Function Function fCalcRATotaal() 'put sum randafwerkingen in reportfooter fCalcRATotaal = dblBDRATotaal dblBDRATotaal = 0 End Function Function fCalcKP(R As Report) 'sum kookplaten Dim tmp As Double tmp = Nz(R!txtPKP, 0) dblKPTotaal = dblKPTotaal + tmp dblTotaal = dblTotaal + tmp fCalcKP = tmp End Function Function fCalcKPTotaal() 'put sum kookplaten in reportfooter fCalcKPTotaal = dblKPTotaal dblKPTotaal = 0 End Function Function fCalcSB(R As Report) 'sum spoelbakken Dim tmp As Double tmp = Nz(R!txtPSB, 0) dblSBTotaal = dblSBTotaal + tmp dblTotaal = dblTotaal + tmp fCalcSB = tmp End Function Function fCalcSBTotaal() 'put sum spoelbakken in reportfooter fCalcSBTotaal = dblSBTotaal dblSBTotaal = 0 End Function Function fCalcB(R As Report) 'sum bewerkingen Dim tmp As Double tmp = Nz(R!txtPB, 0) dblBTotaal = dblBTotaal + tmp dblTotaal = dblTotaal + tmp fCalcB = tmp End Function Function fCalcBTotaal() 'put sum bewerkingen in reportfooter fCalcBTotaal = dblBTotaal dblBTotaal = 0 End Function Function fCalcWP(R As Report) 'sum wandplaten Dim tmp As Double tmp = Nz(R!txtPWP, 0) dblWPTotaal = dblWPTotaal + tmp dblTotaal = dblTotaal + tmp fCalcWP = tmp End Function Function fCalcWPTotaal() 'put sum wandplaten in reportfooter fCalcWPTotaal = dblWPTotaal dblWPTotaal = 0 End Function Function fCalcWPRA(R As Report) 'sum randafwerkingen van wandplaten Dim tmp As Double tmp = Nz(R!txtPWPRA, 0) dblWPRATotaal = dblWPRATotaal + tmp dblTotaal = dblTotaal + tmp fCalcWPRA = dblWPRATotaal End Function Function fCalcWPRATotaal() 'put sum randafwerkingen van wandplaten in reportfooter fCalcWPRATotaal = dblWPRATotaal dblWPRATotaal = 0 End Function Function fCalcE(R As Report) 'sum extra bewerkingen Dim tmp As Double tmp = Nz(R!txtPE, 0) dblETotaal = dblETotaal + tmp dblTotaal = dblTotaal + tmp fCalcE = tmp End Function Function fCalcETotaal() 'put sum extra bewerkingen in reportfooter fCalcETotaal = dblETotaal dblETotaal = 0 End Function Function fTotaal() 'put total in reportfooter fTotaal = dblTotaal End Function I also included a couple of screenshots. In this case the grandtotal is correct, as the subreport Wandplaten is spread over the 2 pages. Only when the title is on page 1, and the first line of the subreport is on page 2, this first line is added twice to the grand total.
Attached File(s)
report_designview.jpg ( 353.83K )
Number of downloads: 5
report_page1.jpg ( 217.01K )
Number of downloads: 4
report_page2.jpg ( 59.01K )
Number of downloads: 4 |
|
|
|
Mar 13 2012, 12:19 PM
Post
#4
|
|
|
UtterAccess VIP Posts: 1,857 From: BC, Canada |
Usually when I need grand totals on a report I have the main report perform the totalling, so the subforms are not involved at all in that process. The layout, and spanning pages, etc. then becomes irrelevant, because the main report gets a copy of the data being reported and does its own calculations.
If there is any complexity involved in the totalling then I might even implement another subform that again does the work but place it in the report footer. As long as the exact same query logic is used you should be able to get the correct figures. Mike |
|
|
|
Mar 14 2012, 09:01 AM
Post
#5
|
|
|
UtterAccess VIP Posts: 1,603 From: Belgium |
Mike,
Thanks for the advice. I already thought of creating an alternative way for calculating the grand total. Still I wonder what is causing this problem. As a test I installed Office2007 on a new machine (OS = XP SP3), applied all Office patches and started the mde, just to see the report with a wrong total. Then I upgraded to Office2010, restarted the machine, opened the same mde and report and now the total is correct. (IMG:style_emoticons/default/iconfused.gif) Given the choice recreating the report and upgrading a couple of installations, I think I'm going to choose the upgrade-path. Cheers. |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 18th May 2013 - 02:41 PM |