运行时错误' 91'向表中添加记录时的VBA访问权限

时间:2016-06-28 11:05:18

标签: sql database vba access

我有一个表格,我想用下面的函数添加记录。 但是当代码执行时,它会抛出运行时错误' 91'

我搜索了所有论坛,但无法解决这个问题。 以下是我的代码:

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

0 个答案:

没有答案