0

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
10
  • Its happening on this: 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');" Commented Jun 28, 2016 at 11:05
  • You have to Set dbs to your database object first. Commented Jun 28, 2016 at 11:16
  • Set dbs = CurrentDb() Commented Jun 28, 2016 at 11:20
  • check this link for related stackoverflow.com/questions/31274060/… Commented Jun 28, 2016 at 11:28
  • 1
    I cant see why loan_ID and Instalment_date are string fields?... and why you want to insert a record that just has the name of the columns? Commented Jun 28, 2016 at 11:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.