set dbs = currentdb()和直接使用currentDB()之间有什么重要区别吗? [英] Is there any important difference between set dbs=currentdb() and using currentDB() directly?

查看:261
本文介绍了set dbs = currentdb()和直接使用currentDB()之间有什么重要区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了很多基本上是这样的代码:

I have inherited a lot of code that is essentially like this:

dim dbs as dao.database
set dbs = currentdb()
dbs.execute "Some SQL string"
set dbs = nothing

是否有任何理由不将其重新编码为:

Is there any reason not to recode it as:

currentdb().execute "some  SQL string"

(我知道,如果我想使用.recordsaffected,currentdb().recordsaffected不会产生可用的结果).

(I know that if I want to use .recordsaffected, currentdb().recordsaffected won't yield usable results).

重新编码除了简化代码之外,还有其他好处吗?

Are there any benefits from recoding it, other than simplifying the code?

推荐答案

仅使用CurrentDb.Whatever是一个诱人的捷径,但是在很多情况下,它会引起奇怪的行为.这是因为CurrentDb本身不是Object,而是一个Function,它返回当前Database对象的副本.

Simply using CurrentDb.Whatever is a tempting shortcut, but there are quite a few circumstances where it causes strange behaviour. That's because CurrentDb is not an Object itself, it is a Function that returns a copy of the current Database object.

几年前,在我调试 是正确的"代码之后,我发誓不再尝试使用CurrentDb,就像它是一个对象一样.创建了一个正确的DAO.Database对象(Set cdb = CurrentDb),并使用cdb.Whatever代替了CurrentDb.Whatever.

Years ago I swore off trying to use CurrentDb like it was an Object after the umpteenth time I was debugging code that I knew was "right", and it was... once I created a proper DAO.Database object (Set cdb = CurrentDb) and used cdb.Whatever instead of CurrentDb.Whatever.

这篇关于set dbs = currentdb()和直接使用currentDB()之间有什么重要区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆