HI I am running a MS Access (2010) macro from Python 2.6.5. It’s running the macro successfully, but the accdb file is not closing all the way correctly. It shows a .laacdb file along with the .accdb file after my macro runs. I figured doing the CloseCurrentDatabase and Quit statements would do this but they are not. The .laacdb file goes away after I restart computer. Thank you.
from win32com.client import Dispatch
strDbName = "C:\\converter\\MainConverter.accdb"
objAccess = Dispatch("Access.Application")
objAccess.Visible = False
objAccess.OpenCurrentDatabase(strDbName)
objDB = objAccess.CurrentDb()
objAccess.DoCmd.RunMacro('Export_to_PDF')
objAccess.Application.CloseCurrentDatabase()
objAccess.Application.Quit
In VBA we routinely set object variables to
Nothingto dispose of them. In Python, try explicitly deleting yourobjAccessvariable.Sorry, my Python is rusty from disuse, so maybe I got the syntax wrong. But something like that may help.
Also, I can’t recall whether you need a pair of parentheses after the
.Quitmethod. Try it like this just in case:In case
objDBis still holding a reference to the Access application/db, delete it too.However, if you’re not actually using it elsewhere in your real code, just eliminate
objDBaltogether.