none
Opening up another .ACCDB file in VBA RRS feed

  • Question

  • I have been trying to open up another existing database through VBA of a current database I have open. I tried this with the workspace.openDatabase method. The code runs, but nothing pops up. I think this method just references that database rather than opens it up.

    Is there anyway to open another database from a current with this method, or another one.

    Here is some code I was playing around with. The arguments in the createworkspace method are from Microsoft offices website. That is the only recourse that I could find on this topic (and even that confuses me).

        Dim wrk As Workspace
        Dim db As Database
        Dim s As String

        s = "Database29.accdb"
        Set wrk = CreateWorkspace("", "admin", "", dbUseJet)

        Set db = wrkAcc.OpenDatabase(s, True)

    If this is all possible, could I use VBA in other office applications to do the same thing?

    Friday, June 30, 2017 6:32 PM

All replies

  • OpenDatabase only loads a database into memory for use by VBA, it does notopen the database into the Access interface.

    If you want to open another database, replacing the currently open database, you can use

    Application.OpenCurrentDatabase("Database29.accdb")

    Keep in mind that the code will instantly stop running after that, because the database containing the code has been closed.

    If you do not want to replace the current database, ask yourself why you want to open two databases in the Access interface...


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Friday, June 30, 2017 6:41 PM
  • Is there anyway to open another database from a current with this method, or another one.

    Hmm, have you tried using Shell or ShellExecute or maybe even Appliation.FollowHyperlink?

    For example:

    Application.FollowHyperlink "c:\FolderName\DatabaseName.accdb"

    Just curious...



    • Edited by .theDBguy Friday, June 30, 2017 7:52 PM
    Friday, June 30, 2017 7:51 PM
  • What are you trying to do with the "Database29.accdb" database? If you only want data from there, you don't need to open it in that manner, you can just link tables in that database to your current database.

    -- Scott McDaniel, Microsoft Access MVP

    Saturday, July 1, 2017 3:57 PM
  • Hi LoganAccess,

    What do you what to do? Show different database in different windows? You could create a new access application instance and open another database using this application instance. So you could open two windows at the same time. Here is the example.

    Option Compare Database
    Dim APP As Access.Application
    Sub TEST()
    Set APP = New Access.Application
    APP.Visible = True
    APP.OpenCurrentDatabase "C:\Users\Documents\Database1.accdb"
    End Sub

    I agree with Scott that you dont need open the database if you just need data in it.

    Best Regards,

    Terry

    Monday, July 3, 2017 6:56 AM
  • Hi LoganAccess,

    Has your original issue been resolved? If it has, I would suggest you mark the helpful reply as answer.
    If not, please feel free to let us know your current issue.

    Best Regards,

    Terry

    Wednesday, August 2, 2017 7:03 AM