Private Sub myButton_Click()
'creates an archive copy of both uncompacted and compacted db's as well as compacting
Dim BE As DBEngine
Dim BackendPath as String
Dim ArchivePath as String
Dim BackendName as String
'note: better not to use mapped drive references as they may not be the same on each machine
BackendPath = "
\\ServerName\DirectoryName\"
ArchivePath = "
\\ServerName\DirectoryName\Archive\"
BackendName="
Backend.accdb"
Set BE = Application.DBEngine
On Error Resume Next
Kill ArchivePath & BackendName 'delete old archive copy
Kill ArchivePath & "CP_" & BackendName 'delete old archive compacted copy
FileCopy BackendPath & BackendName, ArchivePath & BackendName 'copy uncompacted backend to archive
BE.CompactDatabase ArchivePath & BackendName, ArchivePath & "CP_" & BackendName 'compact archive copy to archive directory
Kill BackendPath & BackendName 'delete the working copy of the backend
FileCopy ArchivePath & "CP_" BackendName, BackendPath & BackendName 'copy compacted file to working copy
Set BE=Nothing
End Sub