Opening a new DB with VBA

10,223

If you use the shell then when you close your first database, the second will remain open.

Sub test()
    Dim sh As Variant
    sh = Shell("""C:\...\MSACCESS.EXE"" ""C:\...\FileName.accdb""")
End Sub

My guess the reason your code didn't work is because, the second access you start is an object that exists within the first one. The moment the first one closes and cleanup starts for its objects/variables. It closes the second one.

Share:
10,223
Chuck
Author by

Chuck

Updated on June 04, 2022

Comments

  • Chuck
    Chuck almost 2 years

    I am trying to open another db using VBA from my current db then close the one I am in. When I use the code listed here it opens Access but closes it immediately. I am sure it is simply something I am overlooking but the past hour I have wracked my brain. Any help would be greatly appreciated.

    Private Sub Command115_Click()
    Dim objAccess As Access.Application
    
    Const conPATH = "C:\Users\user\Desktop\Database1.accdb"
    
    'Create an instance of the Access application object.
    Set objAccess = CreateObject("Access.Application")
    
    'Open the database
    objAccess.Visible = True
    objAccess.OpenCurrentDatabase conPATH
    
    'Open the form.
    objAccess.DoCmd.OpenForm "Main-Form"
    
    ' Maximize other Access window
    objAccess.DoCmd.RunCommand acCmdAppMaximize
    End Sub
    

    Thanks in advance for any help in this matter