Hi, I am trying to insert a new record using VB.
It works great however the issue I am having is when I have more than one ID when I run this code it always updates ID1 not ID2, or ID3 and so on.
The table I am updating is a subform on a main form joined by ID. Is there a trick to use the code below but when it is executed it uses the ID of the record I am on?
Many thanks.
Dim db As Database
Dim rec As Recordset
Set db = CurrentDb
Set rec = db.OpenRecordset("Select * from ScheduleT")
rec.AddNew
rec("LoanID") = Forms!LoanF!LoanID
rec("PaymentNumber") = DMax("PaymentNumber", "ScheduleT") + 1 ' Use Dmax to find last payment Number Fen Code this
rec("Residual") = Forms!LoanF!Residual
rec("PType") = "Residual"
rec("DueDate") = Forms!LoanF!EndDate ' Dmax here as well for last payment date +?
rec("Principal") = Forms!LoanF!PaymentAmount
rec("Interest") = rec("Residual") - (DMax("Principal", "ScheduleT") + DMin("Interest", "ScheduleT"))
rec.Update
Set rec = Nothing
Set db = Nothing
Forms!LoanF.Requery
It works great however the issue I am having is when I have more than one ID when I run this code it always updates ID1 not ID2, or ID3 and so on.
The table I am updating is a subform on a main form joined by ID. Is there a trick to use the code below but when it is executed it uses the ID of the record I am on?
Many thanks.
Dim db As Database
Dim rec As Recordset
Set db = CurrentDb
Set rec = db.OpenRecordset("Select * from ScheduleT")
rec.AddNew
rec("LoanID") = Forms!LoanF!LoanID
rec("PaymentNumber") = DMax("PaymentNumber", "ScheduleT") + 1 ' Use Dmax to find last payment Number Fen Code this
rec("Residual") = Forms!LoanF!Residual
rec("PType") = "Residual"
rec("DueDate") = Forms!LoanF!EndDate ' Dmax here as well for last payment date +?
rec("Principal") = Forms!LoanF!PaymentAmount
rec("Interest") = rec("Residual") - (DMax("Principal", "ScheduleT") + DMin("Interest", "ScheduleT"))
rec.Update
Set rec = Nothing
Set db = Nothing
Forms!LoanF.Requery