Sub compactAccess()
Dim fs As Object
Dim strOldPath As String
Dim strNewPath As String
Dim blnSuccess As Boolean
Set fs = CreateObject("Scripting.FileSystemObject")
'Change path and file to suit
strOldPath = "R:\YourFolderPath\YourDatabaseName.mdb"
strNewPath = "R:\YourFolderPath\YourDatabaseName_compacted.mdb"
blnSuccess = Access.Application.CompactRepair(strOldPath, _
strNewPath, True)
fs.CopyFile strNewPath, strOldPath, True
fs.DeleteFile strNewPath
If blnSuccess Then
MsgBox "Compacted Successfully"
Else
MsgBox "The operation did not work"
End If
End Sub