Too many database definitions?

  • Thread starter Thread starter Ron Carr
  • Start date Start date
R

Ron Carr

I am building an app in Access 2000. I have a number of
databases defined, all CurrentDB().
1. Is there a limit as to how often I define a variable as
CurrentDB()?
2. is ther a way to tell if a db definition is already
active so I don't SET it again?
Thanks!
 
I don't think there is a limit. If you're going to use repeated calls to
CurrentDB, then you should cache your reference in a variable:

Dim db As DAO.Database

Set db = CurrentDB

<your code here>

Set db = Nothing

If you're only making one reference to CurrentDB, then there's no gain to be
made by caching your reference. And, you should ALWAYS clean up when you're
through by issuing the =Nothing line ...
 
It depends what you mean. Are you using it like this:
dim db as DAO.Database
set db = CurrentDb

If so, there is no limit to the number of database objects you can create
with this. Generally speaking, they disappear when the code goes out of
scope, that is, when the function and subroutine ends. However, it is good
programming practice to explicitly destroy the database instance like so:
set db = Nothing
You do this just before the subroutine or function ends.
 
Back
Top