View Full Version : Excel code to close an already openend access database

10-22-2015, 10:18 AM
My goal is to close an already opened access database when Excel Opens. Before anyone asks why I am doing this, its because my excel file has a connection tied to this specific db that is opened.
The connection data that my excel file contains does not refresh if the db that is trying to connect is openend. Please help I am not too good with vba.

This one seemed to work but this actually opens the database (a copy) and then closes the copy, not the already opened db:

Dim accessApp As Object
Set accessApp = GetObject("c:path", "Access.Application")
Set accessApp = Nothing

This one does not work and it gives me an error Object required:

Dim accessApp As Object
Dim s As String
s = "c:path"
Set accessApp = GetObject(s)
accessApp = docmd.Quit

10-22-2015, 11:24 PM
you can easily find a solution via googling...

Sub vbax_54070_Close_Access_DataBase_Quit_Access()

Dim objAccess As Object

On Error Resume Next

Set objAccess = GetObject(, "Access.Application")

If Err.Number = 0 Then
objAccess.CloseCurrentDatabase 'to close open database
objAccess.Quit 'to close access application. you dont need previous line if you use this
End If

End Sub

10-23-2015, 12:51 AM
and pls dont duplicate threads
in Access Forum: