Hello,
I am attempting to populate a field named Beginning Amt with the value in a field named Ending Amt from the previous month. The schema and data are as follows...
EFF_DATE SEGMENT ENDING_AMT BEGINNING_AMT
2008-01-01 104777 2350
2008-02-01 104777 6599 2350
Right now I have the following VBA code using the GetRows method looping through 20,000 records twice. This is taking an incredibly long time. Could this be accomplished using a subquery?
Thanks...........ricky
Function PrevMonthAMT()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim RowCount As Long, i As Long, j As Long
Dim SEGMENT As Variant, EFF_DATE As Variant, varData As Variant
Set db = CurrentDb()
Set rs = db.OpenRecordset("AL_EVNT_MANUAL_FINANCIAL", dbOpenSnapshot)
RowCount = rs.RecordCount
varData = rs.GetRows(RowCount)
For i = 0 To RowCount - 1 'GetRows method is zero based
EFF_DATE = varData(0, i)
SEGMENT = varData(2, i)
For j = 0 To RowCount - 1
If varData(0, j) = DateAdd("m", -1, EFF_DATE) And varData(2, j) = SEGMENT Then
varData(4, i) = varData(3, j)
rs.Update
End If
Next j
Next i
rs.Close
I am attempting to populate a field named Beginning Amt with the value in a field named Ending Amt from the previous month. The schema and data are as follows...
EFF_DATE SEGMENT ENDING_AMT BEGINNING_AMT
2008-01-01 104777 2350
2008-02-01 104777 6599 2350
Right now I have the following VBA code using the GetRows method looping through 20,000 records twice. This is taking an incredibly long time. Could this be accomplished using a subquery?
Thanks...........ricky
Function PrevMonthAMT()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim RowCount As Long, i As Long, j As Long
Dim SEGMENT As Variant, EFF_DATE As Variant, varData As Variant
Set db = CurrentDb()
Set rs = db.OpenRecordset("AL_EVNT_MANUAL_FINANCIAL", dbOpenSnapshot)
RowCount = rs.RecordCount
varData = rs.GetRows(RowCount)
For i = 0 To RowCount - 1 'GetRows method is zero based
EFF_DATE = varData(0, i)
SEGMENT = varData(2, i)
For j = 0 To RowCount - 1
If varData(0, j) = DateAdd("m", -1, EFF_DATE) And varData(2, j) = SEGMENT Then
varData(4, i) = varData(3, j)
rs.Update
End If
Next j
Next i
rs.Close