The code below executes okay and does what i want. The thing is
it's damn too slow for a measly 3,000 records this code executes for about 10seconds. What if the records have already reached hundreds of thousands users could probably be waiting the whole day ouch!..
I am looking for suggestion or an alternate code that does the same but executes a lot faster than my code below. hope anyone can help. Thanks in advance
What's the code on the do while loop about:
It is used to determine the number days to get the specific interest value that the client had to pay based on current date and his/her latest payment date if client had already paid. If client has not yet paid, then current date minus the very first transaction date will be used to get the number of days instead.
it's damn too slow for a measly 3,000 records this code executes for about 10seconds. What if the records have already reached hundreds of thousands users could probably be waiting the whole day ouch!..
I am looking for suggestion or an alternate code that does the same but executes a lot faster than my code below. hope anyone can help. Thanks in advance
Code:
On Error GoTo ErrHandler
Dim db As Database
Dim rsRecTo As DAO.Recordset
Dim rsRec As DAO.Recordset
Dim rsDays As Integer
Dim rsDate As Date
Dim lngTranID As Long
Dim intAnswer As Integer
intAnswer = MsgBox("Update interest?", vbYesNo + vbQuestion, "CONFIRM")
Select Case intAnswer
Case vbNo
Exit Sub
Case vbYes
Set db = CurrentDb
DoCmd.Hourglass True
Set rsRecTo = db.OpenRecordset _
("SELECT * FROM tblReceivables WHERE Active = -1")
Do Until rsRecTo.EOF
lngTranID = rsRecTo!TransactionID
If DCount("*", "tblReceivables", "TransactionID = " & lngTranID) = _
DCount("*", "tblReceivables", "TransactionID = " & lngTranID & " And isnull(Paydate)") Then
rsDays = Date - DFirst("TransactionDate", "tblReceivables", "TransactionID = " & lngTranID)
Else
Set rsRec = db.OpenRecordset("tblreceivables", dbOpenDynaset)
rsRec.FindLast "TransactionID = " & lngTranID & " And not isnull(PayDate)"
rsDate = rsRec!PayDate
rsDays = Date - rsDate
End If
With rsRecTo
.Edit
!TotalDays = rsDays
.Update
rsRecTo.MoveNext
End With
Loop
rsRecTo.Close
rsRec.Close
Set rsRecTo = Nothing
Set rsRec = Nothing
Set db = Nothing
DoCmd.Hourglass False
Me.Requery
MsgBox "Update Successful!" & vbCrLf & vbCrLf & _
"Thank you for waiting.", vbInformation, "Interest Update"
End Select
Exit_Now:
DoCmd.Hourglass False
Exit Sub
ErrHandler:
DisplayUnexpectedError Err.Number, Err.Description
Resume Exit_Now
Resume
What's the code on the do while loop about:
It is used to determine the number days to get the specific interest value that the client had to pay based on current date and his/her latest payment date if client had already paid. If client has not yet paid, then current date minus the very first transaction date will be used to get the number of days instead.
Last edited: