MS Access错误91:未设置对象变量或With块变量

时间:2018-05-23 07:35:15

标签: vba ms-access access-vba

错误91:运行此代码时抛出对象变量或With block变量未设置:

Private Sub Cmdsave_Click()
    Dim db As database
    For i = 0 To LISTQTY.ListCount - 1 Step 1
        db.Execute "Updatable tblstock set boxQty = boxQty + " & LISTQTY.Column(1, i) & "  where PID=" & Me.LISTQTY.Column(0, i) & ""
        'CurrentDb.Updatable
    Next
End Sub

1 个答案:

答案 0 :(得分:0)

未设置数据库变量。

Private Sub Cmdsave_Click()
    Dim db As database
    Set db = CurrentDb
    For i = 0 To LISTQTY.ListCount - 1 Step 1
        db.Execute "Updatable tblstock set boxQty = boxQty + " & LISTQTY.Column(1, i) & "  where PID=" & Me.LISTQTY.Column(0, i) & ""
    Next
End Sub

或者只使用CurrentDb

CurrentDb..Execute "Updatable tblstock set boxQty = boxQty + " & LISTQTY.Column(1, i) & "  where PID=" & Me.LISTQTY.Column(0, i) & ""