Compress Access .mdb from Excel?

L

Larry Adams

Is it possible to "compress and repair" an Access database using VBA from
Excel? Would appreciate a code sample if available. Thanks!! Larry.
 
D

Douglas J. Steele

Try something like:

Sub CompactAccess()
Dim objAccess As Object
Dim strBackupFile As String
Dim strDatabaseFile As String

strDatabaseFile = "D:\Folder\File.mdb"
strBackupFile = "D:\Folder\File.bak"
If Len(Dir(strBackupFile)) > 0 Then
Kill strBackupFile
End If
Name strDatabaseFile as strBackupFile

Set objAccess = CreateObject("DAO.DBEngine.36")
objAccess.CompactDatabase strOldFile, strNewFile

Set objAccess = Nothing

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top