VBA访问错误91对象变量或未设置块变量 [英] VBA ACCESS error 91 object variable or with block variable not set
本文介绍了VBA访问错误91对象变量或未设置块变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在一种形式中,当按下一个名为"signal"的按钮时,我想将值插入到一个名为"movimientos"的现有表中.
In a form, when pressing a button called "asignar", I want to insert values to an existing table called "movimientos"
Private Sub ASIGNAR_Click()
Dim db As Database
Dim rs As DAO.Recordset
Set rs = db.OpenRecordset("MOVIMIENTOS")
rs.AddNew
rs("ESTATUSDOC").Value = "Blah"
rs("FOLIOFED").Value = "Blah"
rs("NOMBREDOC").Value = "Blah"
rs("PREL").Value = "Blah"
rs("CURP").Value = "Blah"
rs.Update
End Sub
当我按下运行它继续显示错误:
When I press run it keep showing error:
错误91对象变量或未设置块变量
Error 91 object variable or with block variable not set
推荐答案
我认为您的语法有些偏离,您的代码应如下所示:
I think your syntax is a little off, your code should look like this:
Private Sub ASIGNAR_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("MOVIMIENTOS", dbOpenDynaset, dbAppendOnly)
rs.AddNew
rs("ESTATUSDOC").Value = "Blah"
rs("FOLIOFED").Value = "Blah"
rs("NOMBREDOC").Value = "Blah"
rs("PREL").Value = "Blah"
rs("CURP").Value = "Blah"
rs.Update
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
此问题主要是您声明和设置db
变量的方式.我还调整了OpenRecordset
以匹配您的操作.
The issue is primarily the way that you were declaring and setting your db
variable. I have also adjusted the OpenRecordset
to match what you are doing.
这篇关于VBA访问错误91对象变量或未设置块变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文