Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Access Database from within Another

Status
Not open for further replies.

craigmoran

IS-IT--Management
Oct 23, 2001
3
GB
Does anyone know what is the best way to open one datbase from within another, closing the first database, from clicking a button
 
Craig, you must familiarize yourself with the "Workspace." All databases are opened within a workspace. The default is Workspaces(0). You can create more than one workspace. Within a workspace, more than one database can be accessed.
Give the following a try.


The following example returns a Database variable that points to the current database. Then it opens a different database called Another.mdb by using the OpenDatabase method. The procedure then enumerates all TableDef objects in both databases.
To try this example, create a new database called Another.mdb, close it, and place it in the same directory as the database from which you are running the code.

Sub OpenAnother()
Dim wsp As Workspace
Dim dbs As Database, dbsAnother As Database
Dim tdf As TableDef

' Return reference to current database.
Set dbs = CurrentDb
' Return reference to default workspace.
Set wsp = DBEngine.Workspaces(0)
' Return reference to Another.mdb.
Set dbsAnother = wsp.OpenDatabase("Another.mdb")
' Enumerate all TableDef objects in each database.
Debug.Print dbs.Name & ":"
For Each tdf in dbs.TableDefs

Debug.Print tdf.Name
Next tdf
Debug.Print
Debug.Print dbsAnother.Name & ":"
For Each tdf in dbsAnother.TableDefs
Debug.Print tdf.Name
Next tdf
Set dbs = Nothing
Set dbsAnother = Nothing
End Sub


mac318
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top