vba Access.Application.CurrentDb 是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/417823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 10:09:06  来源:igfitidea点击:

Access.Application.CurrentDb is Nothing?

ms-accessvba

提问by Allain Lalonde

I'm at a loss to explain this one:

我不知道如何解释这个:

I am getting an error:

我收到一个错误:

Error "91" (Object or With block not set)

错误“91”(对象或未设置块)

on the second line below:

在下面的第二行:

Dim rs As DAO.Recordset

Set rs = CurrentDb.OpenRecordset("SELECT * FROM employees")

The following also causes it:

以下也导致它:

`Set rs = CurrentDb.OpenRecordset("employees")`

Executing ?CurrentDb.Namealone in the immediate window causes the error as well.

?CurrentDb.Name在立即窗口中单独执行也会导致错误。

Now, clearly the database is open since I'm editing the form within it, so what can cause this error here?

现在,显然数据库是打开的,因为我正在编辑其中的表单,那么什么会导致此错误?

回答by Birger

If you are working with an ADP project, you should use CurrentProject instead of CurrentDB.

如果您正在处理 ADP 项目,则应使用 CurrentProject 而不是 CurrentDB。

回答by Philippe Grondier

you should assign your .openRecordset method to a dao.recordset object or a generic object ('late binding' technique). try something like this:

您应该将 .openRecordset 方法分配给 dao.recordset 对象或通用对象(“后期绑定”技术)。尝试这样的事情:

dim rs as dao.recordset
set rs = currentDb.openRecordset(your SELECT instruction,...)

回答by Simon Kingston

Try creating a database object and using that instead of the CurrentDb reference. For example:

尝试创建一个数据库对象并使用它而不是 CurrentDb 引用。例如:

Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb
Set rs = db.OpenRecordset("SELECT * FROM Employees")

回答by SQLBobScot

The reason l suspect the code will not work is that according to M/Soft link text'CurrentDb' is a method which will return an 'object variable of type Database'. So the code shown by Forester93 should work. Its what l would use and have been using for many years now.

我怀疑代码不起作用的原因是,根据 M/Soft链接文本“CurrentDb”是一种将返回“数据库类型的对象变量”的方法。所以 Forester93 显示的代码应该可以工作。它是我会使用的并且已经使用了很多年。