469,076 Members | 1,422 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,076 developers. It's quick & easy.

Open one Access database from another

I am creating a utility database to use to update and maintenance other databases. One of them has an update process that uses 19 queries and as many linked tables. It works, but is complicated (and undocumented), so I would rather just have a button that opens that database.

I would prefer opening a specific form, but that is optional.

Here is some code (MSDN) I found that gets as far as opening the database, but once you click "Open" nothing happens.

Expand|Select|Wrap|Line Numbers
  1. Dim appAccess As Access.Application
  2.     Dim strDB as String
  4.     ' Initialize string to database path.
  5.     Const strConPathToSamples = "C:\Program " _
  6.         & "Files\Microsoft Office\Office11\Samples\"
  8.     strDB = strConPathToSamples & "Northwind.mdb"
  9.     ' Create new instance of Microsoft Access.
  10.     Set appAccess = _
  11.         CreateObject("Access.Application")
  12.     ' Open database in Microsoft Access window.
  13.     appAccess.OpenCurrentDatabase strDB
  14.     ' Open Orders form.
  15.     appAccess.DoCmd.OpenForm "Orders"
Any help would be great.

Jul 29 '08 #1
2 19397
112 Expert 100+
The following code is a function that returns the access application. To use this you would set an application object variable to the return value of this function:
Expand|Select|Wrap|Line Numbers
  1. Function OpenDB(DatabasePath As String) As Access.Application
  2.     Dim app As Access.Application
  3.     Set app = New Access.Application
  4.     app.OpenCurrentDatabase DatabasePath
  5.     Set OpenDB = app
  6. End Function
For instance:
Expand|Select|Wrap|Line Numbers
  1. Sub Main()
  2.     Dim app As Access.Application
  3.     Set app = OpenDB("C:\SomeDatabaseOnYourComputerOrNetwork.mdb")
  4. End Sub
You will then have access to the complete Access object model via the app variable. If you want to be able to see the application then you can set its visible property to true like so:
Expand|Select|Wrap|Line Numbers
  1. app.Visible = true
That might get you started. Let me know if you have any questions.
Jul 29 '08 #2
32,154 Expert Mod 16PB
Application Automation may help as a reference.
Aug 5 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by dennist685 | last post: by
24 posts views Thread by dancer | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.