databasems-accessvbams-access-2007

Closing a database using VBA code from a seperate database


Is it possible to close one Access database (let's call it Database A) via VBA code from another Database (Database B).

In the example here, if Database A is open when Database B launches, I would want Database A to close. Is this possible using VBA?

I've had a google about, but all answers seem to be related to closing the current database using VBA, which of course I could achieve with DoCmd.Quit.

Any help is greatly appreciated.


Solution

  • You can hijack it:

    Dim OtherDB As Object
    
    sOther = "Z:\Documents\other.accdb"
    Set OtherDB = GetObject(sOther)
    OtherDB.Application.Quit
    

    It may make life difficult for someone.