CurrentDb

Kiwi-Wombat

Registered User.
Local time
Today, 07:30
Joined
Aug 2, 2004
Messages
56
HI folks

I see this code commonly

Dim db As Database
Dim rst As Recordset
Set db = CurrentDb
Set rst = db.OpenRecordset("yourTableName")

To what does CurrentDb refer? Does it refer to an actual table that is open or is it an object like 'Recordset' and 'Database'?

I previously posted a question about a form with 4 unlinked tables. Pat Hartman kindly assisted with that query but it means the the form has no recordsource. The listboxes on the form individually look at their respective tables.

So if CurrentDb means an actual open table which one does it refer to?

Thanks
 
I believe that the CurrentDb = the current database that your code resides in.
 
Not sure I understand

If the code is on the form which has no source, and there are 4 separate databases as queries on the listbox sorurce which is the CurrentDb?
 
kiwi,

CurrentDb is the database that you are using (the .MDB file that you
launched).

You must instantiate (or open) a database object to reference its
components Tabledefs, QueryDefs, RecordSets ...

Dim dbs As Database <-- dbs WILL BE (later) a database type object
Set dbs = CurrentDb <-- Set it to the current database

From now on referencing dbs.TableDefs, for instance, will be referring to
the collection of TableDefs within your current database.

You can declare a database object.
Set it to an "external" database.
Then refer to the other database's: Tabledefs, QueryDefs, RecordSets ...

btw, do you really have a listbox with its RowSource equal to 4 databases?
How about four tables?

Wayne
 
Sorry - I meant to say 4 separate tables with a listbox for each

Thanks for your answer, all clear now. I saw CurrentDb and immediately thought of a table rather than the actual .mdb file
 

Users who are viewing this thread

Back
Top Bottom