变量在与 DAO 一起使用之前未声明
我正在使用 DAO(被要求不要使用 ADO.NET)来更新 Access 数据库。然而,到目前为止,VB2008 告诉我变量“daoengine”在使用之前没有声明。我在下面的代码中做错了什么?
Function update_db()
Dim daoengine As DAO.DBEngine
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
dbs = daoengine.OpenDatabase("Project.mdb")
rst = dbs.OpenRecordset("Log", dao.RecordsetTypeEnum.dbOpenDynaset)
End Function
I'm using DAO (been asked not to use ADO.NET) to update an Access database. I'm currently thus far, however, VB2008 is telling me that the variable "daoengine" is not declared before it is used. What am I doing wrong in the following code?
Function update_db()
Dim daoengine As DAO.DBEngine
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
dbs = daoengine.OpenDatabase("Project.mdb")
rst = dbs.OpenRecordset("Log", dao.RecordsetTypeEnum.dbOpenDynaset)
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你应该有
而不是
You should have
instead of
当你说
你只是创建一个变量
daoengine
时,但它实际上并不指向任何东西。之后您需要执行此操作:您也可以输入
Dim daoengine As New DAO.DBEngine
,但最好在上面的两行中执行此操作。如果您将New
放在Dim
行中,您就创建了所谓的“自动实例化”变量,该变量可以在您认为已处理掉之后神奇地再次生效它。有关更多详细信息,请参阅此处的不要使用自动实例化对象变量:声明变量(在 VBA 中)
When you say
you're just creating a variable,
daoengine
, but it doesn't actually point to anything. You need to do this afterwards:You can also type
Dim daoengine As New DAO.DBEngine
, but it's better to do it in the two lines above. If you put theNew
in theDim
line, you create what's called an "auto-instancing" variable which can magically come to life again after you thought you'd disposed of it.For more details see the Don't Use Auto-Instancing Object Variables here: Declaring Variables (in VBA)