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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to open another database from the existing one?

Status
Not open for further replies.

siebel2002

Programmer
Oct 8, 2001
102
US
Help, Please!

I have a command button in my access database with the following code for the onclick event. My need is to open the Employees database.

Sub cmdEmployessDatabase_Click()
Dim strPath As String
strPath = "C:\MyFolder\Employees.mdb"
OpenCurrentDatabase strPath
DoCmd.OpenForm "Employees", acNormal
End Sub

I dont see the database opening!! Please help!
 
If you made the Employees form the startup form for the Employees database perhaps this would do the trick

Code:
Sub OpenDB(strTloc As String)

   'Define as Static so the instance of Access
   'doesn't close when the procedure ends.
   Static acc As Access.Application
   Dim db As DAO.Database
   Dim strDbName As String
On Error GoTo Err_OpenDB
   strDbName = "C:\MyFolder\Employees.mdb
   Set acc = New Access.Application
   acc.Visible = True
   Set db = acc.DBEngine.OpenDatabase(strDbName, False, False)
   acc.OpenCurrentDatabase strDbName
   db.Close
   Set db = Nothing
 
This is all you need

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("Your.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


You copy it in first - it will open whole 9 yards of second

TIA
 
The Shell command also works.

Private Sub Command29_Click()
'Open another databse

Shell "C:\Program Files\Microsoft Office\Office\msaccess.exe " & "FullPathName", vbMaximizedFocus
Application.Quit
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top