Dear all,
This code below compacts the access database, but is it possible to do
it in vba code from excel?
Sub compact_bd()
Dim strDBtoBackUp As String
strDBtoBackUp = ThisWorkbook.Path & "\bd.mdb"
DBEngine.CompactDatabase strDBtoBackUp
End Sub
Thanks a lot!!!
André.
Create a reference in the Excel workbook to the appropriate DAO
object. In Excel 2007, it would be "Microsoft Office 12.0 Access
Database Engine Object Library"
In Excel 2003, I think it is DAO 3.5 or DAO 4. Can't recall off
the top of my head.
Then, the following code will do it.
Sub CompactAccessDatabase()
Dim szSourceDatabase As String
Dim szDestinationDatabase As String
szSourceDatabase = "C:\Filename.accdb"
szDestinationDatabase = "C:\Compacted.accdb"
DBEngine.CompactDatabase szSourceDatabase, szDestinationDatabase
End Sub
You might be able to play with it and get it to use the source
and destination as the same so it compacts over itself like
Access does when you manually compact without having to create a
destination database as I have done above. If not, just a few
more lines of code to delete the source and rename the
destination with the source name.
--
__________________________________________________________________________________
Ed Hansberry (Please do *NOT* email me. Post here for the benefit of all)
What is on my Pocket PC?
http://www.ehansberry.com/
Microsoft MVP - Mobile Devices
www.pocketpc.com
What is an MVP? -