Hello all,
I am working on an amortization schedule in which I am attempting to create a function that will apply extra payments to any past due amounts before they are applied to the principal. I have muddled through this so far (it's ugly, so please no criticisms, I'm TRYING):
Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strsql As String
strsql = "SELECT ScheduleT.PaymentNumber, ScheduleT.PaidDate, ScheduleT.LoanID, ScheduleT.RegularPayment, ScheduleT.DueDate, ScheduleT.Pay, ScheduleT.AmountPaid, ScheduleT.AmountDue " & vbCrLf & _
"FROM ScheduleT " & vbCrLf & _
"WHERE (((ScheduleT.PaymentNumber) Is Not Null) AND ((ScheduleT.PaidDate) Is Null) AND ('(ScheduleT.LoanID)=[Forms]![PaymentForm]![LoanID]') AND ((ScheduleT.RegularPayment)=0) AND ((ScheduleT.DueDate)<=Date())) " & vbCrLf & _
"ORDER BY ScheduleT.DueDate;"
Recordset.Filter = "loanid = me.loanid and rs.paymentnumber<>null"
Set db = CurrentDb
Set rs = db.OpenRecordset(strsql)
rs.MoveFirst
Do While ((LoanID) = [Forms]![paymentform]![LoanID]) And ((RegularPayment) = 0) And ((DueDate) <= Date)and([Forms]![paymentform]![amountleft]>0)
Me.PaidDate = Forms!paymentform!datepaid
Me.RegularPayment = Forms!paymentform!PaymentAmount
Me.AmountPaid = Forms!paymentform!PaymentAmount
Me.Requery
addtopaymenttable
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Sub
This will apply a payment to ALL past due amounts, regardless of the actual amount paid. IE. Say someone is behind 4 months with a total of $348.96 due to date, and they pay $300, my function posts a payment to every month, totaling 348.96 instead of just until the $300 is used up. I just can't get my head around it, to make it stop when $300 is gone, or how to apply the extra if they pay $400. This is my first real attempt at using recordsets, please be gentle.
TIA! Have a great day!