I have a table where I want to add records using the below function. But when the code executes, it throws Run-Time Error '91'
I've searched all the forums but can't work this out. Below is my Code:
Private Sub CmdCreateLoan_Click()
Dim tempinstal As Integer
Dim tempdate As Date
Dim StrSQL As String
Dim dbs As Database
On Error GoTo 0
If Me.Loan_Status = 10 Then
MsgBox "Loan Successfully Created", , "Loan Created"
Me.Loan_Status = 9
DoCmd.Save
DoCmd.OpenQuery "que_addinstalment", acViewNormal
tempinstal = Me.No_Instalments - 1
tempdate = DateAdd("m", 1, Me.First_Payment_Date)
Do While tempinstal > 0
Set dbs = CurrentDb
dbs.Execute " INSERT INTO [tblinstalments] " _
& "(Loan_ID,Instalment_Date, Total_Instalment,Capital_Instalment,Interest_Instalment,Next_Balance) VALUES " _
& "('loan_ID','tempdate','instalment','Capital_Instalment','interest_instalment','next_Balance');"
dbs.Close
Set dbs = Nothing
tempinstal = tempinstal - 1
tempdate = DateAdd("m", 1, tempdate)
Loop
DoCmd.Close
Else
MsgBox "Loan Contract not Printed. Please Print before proceeding", , "Print Loan Contract"
End If
End Sub
Set dbsto your database object first.dbs = CurrentDb()loan_IDandInstalment_dateare string fields?... and why you want to insert a record that just has the name of the columns?