D
David W. Fenton
Of course, it does. But I think it's not a matter for the OP in
the first line.
The more the function is going to be used, the more it needs to be
robust and efficient.
This is the normal behavior.
Yes, of course it's the normal behavior, but you have to know that
even if your variable/function/property is initialized with
CurrentDB it needs to be refreshed if you're changing collections.
But a new variable assignment from CurrentDB() will *not* need to
have the collections refreshed, because you're getting an entirely
new instance, with already-refreshed collections.
It's just if you're using one set *before* the collections were
changed that you need to refresh, just as you would with a db
variable initialized with DBEngine(0)(0).
That's the problem of CurrentDb. It changes, but not that much:
Dim db1 As DAO.Database
Dim db2 As DAO.Database
Set db1 = CurrentDb
Set db2 = CurrentDb
If db1 Is db2 Then
MsgBox "equal"
Else
MsgBox "NOT equal"
End If
That's not a difference in the database pointed to by CurrentDB --
it's only a difference in the *memory address* of the pointer to it.
And that is *irrelevant*.
Again, there is never any reason to us CurrentDB() in a loop, as the
database it refers to can never be different from one iteration of
the loop to the next. Thus, there is no cumulative performance
penalty in using CurrentDB() over DBEngine(0)(0) that makes a
difference in real-world application programming. It only makes a
difference if you set up an artificial structure that should never
happen in a well-designed application.