On Error Resume Next Dim accessApp Set accessApp = CreateObject("Access.Application") Dim dbPath dbPath = "C:\Users\alexi\Documents\projects\timetrack-pro\db\TimeTrackPro.accdb" Dim tempPath tempPath = "C:\Users\alexi\Documents\projects\timetrack-pro\db\TimeTrackPro_temp.accdb" WScript.Echo "Compacting and repairing database..." ' Compact and repair accessApp.CompactRepair dbPath, tempPath If Err.Number = 0 Then WScript.Echo "Success! Replacing original file..." Dim fso Set fso = CreateObject("Scripting.FileSystemObject") ' Delete original If fso.FileExists(dbPath) Then fso.DeleteFile dbPath End If ' Rename temp to original fso.MoveFile tempPath, dbPath WScript.Echo "Database compacted and repaired!" Else WScript.Echo "Error: " & Err.Description End If accessApp.Quit Set accessApp = Nothing