# Open db from another Access db



## Plukey

Trying to open a different access db from my Data base using button /  VBA. The code opens the db but i get an error after. If anyone knows an easier way, I'm open to ideas. 



		VBA Code:
__


Dim accapp As Access.Application
 
Set accapp = New Access.Application
 
accapp.OpenCurrentDatabase ("C:\PATH")

This is the error Im getting afyter the Data base opens


----------



## Joe4

Why are you trying to do this?
What is the automate goal here?

If you just want access to the data in the other database, a better option may be to just link the tables from the one database to the other.


----------



## Plukey

Joe4 said:


> Why are you trying to do this?
> What is the automate goal here?
> 
> If you just want access to the data in the other database, a better option may be to just link the tables from the one database to the other.


I have a set of shortcuts on the main page for users to use. Its just another database to use as a tool for our work. The company recently updated/upgraded the database with a new path on ouR shared drive. I replaced the path & it opens but I get that message now.


----------



## jackd

More info please. List the steps you envision for using this approach.

I used the following in opening  other databases and listing all tables.
Hope it's helpful..




		VBA Code:
__


'---------------------------------------------------------------------------------------
' Procedure : Multi_MDBs
' Author    : user
' Date      : 3/30/2008
' Purpose   : Used to identify linked tables in a list of databases.
'---------------------------------------------------------------------------------------
'
Sub Multi_MDBs()
      Dim ThisDB As DAO.Database
      Dim otherDB As DAO.Database
      Dim strDbPath As String
      Dim rs As Recordset
      Dim rz As Recordset

      Dim tdf As TableDefs
      Dim i As Integer
      Dim MyBEPath As String
      Dim strMsg As String
      Dim sResponse As Variant
10       On Error GoTo Multi_MDBs_Error

20    On Error Resume Next
      Dim tbl As TableDef
30       On Error Resume Next
       
40    Set ThisDB = CurrentDb

50    Set rs = ThisDB.OpenRecordset("Select fullMDBCoord from A2Kmdbs")
60    Open "c:\jack\LinkedTbls.log" For Append As #1
70    Do While Not rs.EOF
80    blnTitlePrinted = False

90        Debug.Print Now & " - Processing  " & rs!fullmdbcoord
         ' If rs!fullmdbcoord <> "D:\A2K\db1_Backup.mdb" Then
         ' GoTo MoveIt
         ' End If
100       strDbPath = rs!fullmdbcoord
110      Set otherDB = OpenDatabase(strDbPath)
120      Set tdf = otherDB.TableDefs
130      Debug.Print "Checking tables in "; otherDB.name & vbTab & Now()
140   For i = 0 To tdf.Count - 1
150   MyBEPath = Mid(tdf(i).Connect, 10)
160   Debug.Print tdf(i).name
.....,.


----------



## Micron

What I don't get here is the idea of trying to open a vbs file as an Access db. Or is it just that there's too much code missing to see what's really going on? 
I don't think that saying what the 2nd db is or is used for really answers the question of why.


----------



## Plukey

Micron said:


> What I don't get here is the idea of trying to open a vbs file as an Access db. Or is it just that there's too much code missing to see what's really going on?
> I don't think that saying what the 2nd db is or is used for really answers the question of why.


Apologies for any confusion... Novice here!

Our group has a database we use for our job function. On our main page there are a list of shortcuts. Im using an Event procedure on the label to open another Db in our shared network. Our department recently updated the Db due to a few issues. They changed the path, i replaced the path and it does open the Db but gives the error above after it opens.



		VBA Code:
__


Private Sub Label442_Click()
Dim accapp As Access.Application
 
Set accapp = New Access.Application
 
accapp.OpenCurrentDatabase ("C:***********************.accde")

End Sub


----------



## Micron

More confusion. You edited posted code to show you're trying to open accde file yet the message says it can't open a vbs file.
In my Access version, labels don't have events. I doubt they ever did either.


----------



## Plukey

Micron said:


> More confusion. You edited posted code to show you're trying to open accde file yet the message says it can't open a vbs file.
> In my Access version, labels don't have events. I doubt they ever did either.


----------



## Micron

You're right. _Attached_ labels don't have events. Unattached to. My gray matter is not what it used to be - apologies.
Still, that doesn't seem to reveal why the file in code is accde but the message refers to a vbs file.
Maybe the opened database is where the error is being raised from, and it has something to do with the broad changes that you mentioned.


----------



## Plukey

Micron said:


> You're right. _Attached_ labels don't have events. Unattached to. My gray matter is not what it used to be - apologies.
> Still, that doesn't seem to reveal why the file in code is accde but the message refers to a vbs file.
> Maybe the opened database is where the error is being raised from, and it has something to do with the broad changes that you mentioned.


Yea, i agree totally...Im gonna put this one on the back burner & get with the department that developed the new Db
thanks everyone! Sorry if i wasted anyone's time today!


----------



## Plukey

Trying to open a different access db from my Data base using button /  VBA. The code opens the db but i get an error after. If anyone knows an easier way, I'm open to ideas. 



		VBA Code:
__


Dim accapp As Access.Application
 
Set accapp = New Access.Application
 
accapp.OpenCurrentDatabase ("C:\PATH")

This is the error Im getting afyter the Data base opens


----------



## Plukey

Problem fixed...there was a hyperlink that opened the original Db that i missed. Once i removed that it worked as it should... sorry i should've caught that.


----------

