Is there any important difference between set dbs=currentdb() and using currentDB() directly?

后端 未结 1 1222
孤城傲影
孤城傲影 2020-12-20 20:51

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         


        
相关标签:
1条回答
  • 2020-12-20 21:36

    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.

    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.

    0 讨论(0)
提交回复
热议问题