• Closing a second database (A2000)

    Author
    Topic
    #365681

    I have to Open and Close a database from another database so that the Compact On Close Option will execute. I have tried
    Dim MyDb as DAO.Database
    Set MyDb = OpenDatabase(“PathToDb”)
    MyDb.Close
    which doesn’t do it.
    I have tried opening the file using the Shell Function and that opens it fine, but I can’t close it. Anyone know how I would close the db after opening it using the Shell Function. Or anyother ideas.
    Thanks
    Paul

    Viewing 0 reply threads
    Author
    Replies
    • #565018

      Hi Paul,

      As always, there are several ways to get the job done. You’re using DAO Objects to open the database. In this case, I would use Access Automation code:

      Sub OpenDatabase()    
           Dim appAccess As Access.Application
           Set appAccess = CreateObject("Access.Application")
           'Replace database file and path with your own        
           appAccess.OpenCurrentDatabase "D:My DocumentsYourDatabase.mdb", True
           'Insert your code
           appAccess.Quit    
           Set appAccess = Nothing
      End Sub

      HTH thumbup

      • #565019

        Thank you Mark. I was just coming back to say I got the answer and the answer was exactly what you posted. Thanks very much.
        Paul

    Viewing 0 reply threads
    Reply To: Closing a second database (A2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: