I’m trying to make a small VBScript that compacts a MS Access 2007 database file.
The code I have is:
Set acc2007 = CreateObject("DAO.DBEngine.36")
acc2007.CompactDatabase "C:\test.accdb", "C:\test2.accdb", Nothing, Nothing, ";pwd=test"
Set acc2007 = Nothing
I’m getting this error when I run the three lines with “cscript test.vbs” from a 32-bit cmd.exe:
C:\test.vbs(10, 1) DAO.DbEngine: Unrecognized database format ‘C:\test.accdb’.
The database was created with MS Access 2007, when I open it by double-clicking the icon I type the password “test” and then i opens normally. It says “Access 2007” at the top so it has the correct format.
Here’s documentation of the function I’m trying to use: http://msdn.microsoft.com/en-us/library/bb220986.aspx
The object DAO.DBEngine.36 is created successfully since I’m not getting any errors on that line. What can be wrong?
DAO 3.6 does not support the new ACCDB database format. Try
DAO.DBEngine.120instead.Here is an example which works on my system.
Note: I decided to make a backup of my database before compact. At the end, I remove the original (uncompacted) database and rename the compacted one to the original name. If you’re not interested in that, you could simplify this by removing the
objFSOstuff.Edit: Revised to check for lock file; if found do nothing.