CurrentMonth = Month(CurrentDate)
CurrentYear = Year(CurrentDate)
SQL = "SELECT Spent, MONTH(Date) AS InvMonth, YEAR(Date) As InvYear FROM Invoices WHERE YEAR(Date) = '" & CurrentYear & "' AND MONTH(Date) = '" & CurrentMonth & "'"
RecordSet.Open SQL, Connection, adOpenStatic, adLockOptimistic, adCmdText
Do Until RecordSet.EOF
MTotal(i) = MTotal(i) + RecordSet.Fields("Spent")
RecordSet.MoveNext
Loop
RecordSet.Close
This is the code I currently have to build up a total spent for a given month. I wish to expand this to retrieve the totals per month, for the past 12 months.
The way I see to do this would be to loop backwards through the CurrentMonth value, and if CurrentMonth value reaches 0 roll the value of CurrentYear back 1. Using the loop variable (i) to build up an array of 12 values: MTotal()
What do you guys think?