Open one Access database from another

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bard777
    New Member
    • Jan 2008
    • 23

    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.

    Code:
    Dim appAccess As Access.Application
        Dim strDB as String
    
        ' Initialize string to database path.
        Const strConPathToSamples = "C:\Program " _
            & "Files\Microsoft Office\Office11\Samples\"
    
        strDB = strConPathToSamples & "Northwind.mdb"
        ' Create new instance of Microsoft Access.
        Set appAccess = _
            CreateObject("Access.Application")
        ' Open database in Microsoft Access window.
        appAccess.OpenCurrentDatabase strDB
        ' Open Orders form.
        appAccess.DoCmd.OpenForm "Orders"
    Any help would be great.

    Thanks,
    Bard
  • janders468
    Recognized Expert New Member
    • Mar 2008
    • 112

    #2
    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:
    Code:
    Function OpenDB(DatabasePath As String) As Access.Application
        Dim app As Access.Application
        Set app = New Access.Application
        app.OpenCurrentDatabase DatabasePath
        Set OpenDB = app
    End Function
    For instance:
    Code:
    Sub Main()
        Dim app As Access.Application
        Set app = OpenDB("C:\SomeDatabaseOnYourComputerOrNetwork.mdb")
    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:
    Code:
    app.Visible = true
    That might get you started. Let me know if you have any questions.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32634

      #3
      Application Automation may help as a reference.

      Comment

      Working...