Ajax,
Thanks for the info.
I modified some of the Trandate values. I then saw the difficulty with the ID values not following the <=.
My attempt then was to redesign EagleBill and create a new table EagleBill2.
For EagleBill I changed the autonumber to Number and renamed the field from Id to IDOLD. For EagleBill2, I added a new field ID. I populated EagleBill2 using this query
Code:
INSERT INTO EagleBill2 ( IDOld, trandate, credit, debit )
SELECT IDOld, trandate, credit, debit
FROM EagleBill
ORDER BY EagleBill.tranDate;
The above query added the autonumber ID based on ascending TranDate.
The original query was adjusted:
Code:
SELECT eaglebill2.id, eaglebill2.TranDate, eaglebill2.Credit, eaglebill2.Debit
, Format(DSum("Nz(Credit,0) - NZ(Debit,0)","eaglebill2","ID<=" & ID),"Currency") AS RunningBalance
FROM eaglebill2
ORDER BY ID;
The routine to check execution was modified
Code:
Sub ToProcessEagleBillRecords()
Debug.Print "Processing " & CurrentDb.TableDefs("Eaglebill2").RecordCount & " records from EagleBill2"
Dim timer As clsTimer
Set timer = New clsTimer
timer.StartTimer
DoCmd.OpenQuery "RunningTot_EagleBill"
Debug.Print "Completed the query in " & timer.EndTimer & " ~millisecs" & vbCrLf & Now
Set timer = Nothing
End Sub
The result summary is:
Processing 7918 records from EagleBill2
Completed the query in 36 ~millisecs
24/11/2015 7:53:05 PM
Here are some records of the output:
Code:
id |
TranDate |
Credit |
Debit |
RunningBalance |
2 |
15/10/2015 |
$100.00 |
|
$200.00 |
3 |
17/10/2015 |
|
$100.00 |
$100.00 |
4 |
24/10/2015 |
$100.00 |
|
$200.00 |
5 |
24/10/2015 |
$100.00 |
|
$300.00 |
6 |
02/11/2015 |
$200.00 |
|
$500.00 |
7 |
02/11/2015 |
$100.00 |
|
$600.00 |
8 |
03/11/2015 |
|
$100.00 |
$500.00 |
9 |
04/11/2015 |
$300.00 |
|
$800.00 |
10 |
06/11/2015 |
$400.00 |
|
$1,200.00 |
11 |
06/11/2015 |
|
$300.00 |
$900.00 |
12 |
07/11/2015 |
|
$200.00 |
$700.00 |
13 |
08/11/2015 |
$200.00 |
|
$900.00 |
14 |
22/11/2015 |
$100.00 |
|
$1,000.00 |
15 |
22/11/2015 |
$100.00 |
|
$1,100.00 |
16 |
22/11/2015 |
|
$100.00 |
$1,000.00 |
17 |
23/11/2015 |
|
$100.00 |
$900.00 |
18 |
23/11/2015 |
$100.00 |
|
$1,000.00 |
19 |
23/11/2015 |
$100.00 |
|
$1,100.00 |
20 |
23/11/2015 |
$100.00 |
|
$1,200.00 |
21 |
24/11/2015 |
$100.00 |
|
$1,300.00 |
22 |
24/11/2015 |
|
$100.00 |
$1,200.00 |
23 |
24/11/2015 |
$100.00 |
|
$1,300.00 |
24 |
24/11/2015 |
$100.00 |
|
$1,400.00 |
25 |
24/11/2015 |
$100.00 |
|
$1,500.00 |
I'm not sure that I fully understand the underlying issue. My thoughts are to get the ID ascending and to account for differing dates. I hope it's useful.