Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Location
    Swindon, UK
    Posts
    86

    Red face Unanswered: Open a database from code

    I need to know how to open an Access97 database from code within an Access97 database. I then need to be able to close the original database. I am currently using the below code, but the database i open, closes as soon as it gets to the End Sub

    Sub OpenDb
    Dim accApp As Access.Application

    Set accApp = CreateObject("Access.Application")
    accApp.OpenCurrentDatabase "C:\MyDb.mdb"

    End Sub

  2. #2
    Join Date
    Jan 2003
    Location
    Aberdeen, Scotland, UK
    Posts
    168

    Re: Open a database from code

    It's a bit strange. Automation to Excel does the same thing unless you open a workbook as well as the app. If you open a form in the new database it stays open.

    I tried the following and it kept the new instance open.

    Sub OpenDb
    Dim accApp As Access.Application

    Set accApp = CreateObject("Access.Application")
    accApp.OpenCurrentDatabase "C:\MyDb.mdb"
    accApp.DoCmd.OpenForm "FormName"
    End Sub

    John
    J.

  3. #3
    Join Date
    Feb 2004
    Location
    Swindon, UK
    Posts
    86
    Cheers John, However, this worked the first time i tried it, but now it goes back to closing the second database again, as soon as it gets to the End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •