I have an Access VBA project that I am working on and it involves Looping. I have three fields Fund #, Effective date, and Total Amount. I am trying to create a VBA code that will loop via the account ID and sum up the Total Amounts based off the Fund Activity in the last 5 days (effective Date). Basically, my in input from my table looks like this.
Fund: Effective Date, Total Amount
586 01/02/2015 -454
586 01/03/2015 -454
586 01/04/2015 -454
586 01/05/2015 -454
586 01/06/2015 -854
586 01/07/2015 -954
586 01/08/2015 -254
586 01/09/2015 -154
586 01/10/2015 -654
586 01/13/2015 -354
486 01/02/2015 -954
486 01/03/2015 -954
486 01/05/2015 -954
486 01/07/2015 -954
486 01/09/2015 -954
486 01/010/2015 -954
The VBA will identify the fund number. Will look at the date and sum up funds total outflow in the last five days using the effective date. Then the loop will go back to the second date and add the next five days total outflow for that fund, once it's done looping st 5 days it will move to the next date etc. Once it completes looping via that fund #, it will move to the next fund # and do the same thing as mentioned fund above
The goal is to insert the final output into another table and will look something like this
Id Date , ID Amount1, ID Amount1, ID Amount1, ID Amount1, Largest Redemption week date
Fund # Id Date , 01/02- 1/07 01/03- 1/08 01/04- 1/09 01/05- 1/10,
Etc Largest Redemption
Date Largest Redemtption Week Amount
44 -20788 -5788 -10500 5885 12/20/2014 -45855
88 -10788 -2788 -8500 3885 06/30/2014 -50000
60 -13788 -2788 -2500 1885 06/30/2014 -25000
So the final output will be inserted into another table and will look something like this
This is what I have so far.. I need to create a Access vba code so will give me the out put above. Thanks for you help
Option Compare Database
Function OpenRecordset()
Dim dbsArchive As Database Dim rs As DAO.Recordset Dim rs2 As DAO.Recordset Dim i As Double Dim x As Double Dim StrSQL As String Dim strFund As String Dim strCriteria As String Dim AddFundCriteria As Double Dim FirstMark As Variant Dim IDFund As Double Dim IDDate As Double
Set dbsArchive = CurrentDb Set rs = dbsArchive.OpenRecordset("2014")
For i = 0 To rs.RecordCount - 1 strFund = rs.Fields("Link_Fund")
StrSQL = "SELECT [USysD07366-2014].LINK_FUND, [USysD07366-2014].SUPER_SHEET_DATE," & _
"Sum([USysD07366-2014]![REDEMPT]+[USysD07366-2014]![EXCHANGE OUT]) AS RedemptionTotal " & _
"FROM [USysD07366-2014] " & _
"GROUP BY [USysD07366-2014].LINK_FUND, [USysD07366-2014].SUPER_SHEET_DATE " & _
"HAVING ((([USysD07366-2014].LINK_FUND) = " & strFund & ")) " & _
"ORDER BY [USysD07366-2014].SUPER_SHEET_DATE; "
Set rs2 = dbsArchive.OpenRecordset(StrSQL, dbOpenSnapshot)
For x = 0 To rs2.RecordCount - 1
' strCriteria = "Link Fund = " & rstCategories![Link Fund]
Debug.Print rs2.Fields("Link_Fund")
Debug.Print rs2.Fields("SUPER_SHEET_DATE")
Debug.Print rs2.Fields("RedemptionTotal")
rs2.MoveNext
Next x
rs.MoveNext
Next i
rs.Close
rs2.Close
Set rs = Nothing
Set rs2 = Nothing
dbsArchive.Close
ErrorHandler: MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
End Function