Forum Discussion
lytell
May 06, 2021Copper Contributor
Compact & Repair throws error saying file is in use
When trying to compact and repair any database created on my computer i get an error saying file is already in use. I have tried every possible way to fix this - reinstalled Office 365 tried multiple...
isladogs
May 07, 2021MVP
Create a function similar to this in a standard module
It should work whether or not the target database to be compacted is open as a backup copy is made and then the copy is compacted
Public Function CompactTargetDatabase()
'creates a compacted copy of the target database
Dim fso As Object
Dim strOldPath As String, strNewPath As String, strTempPath As String
Set fso = CreateObject("Scripting.FileSystemObject")
strOldPath = "full path to target database to be compacted"
strTempPath = "full path for temporary copy of target database"
strNewPath = "full path for compacted copy of target database"
'copy database to a temp file
fso.CopyFile strOldPath, strTempPath
Set fso = Nothing
'compact the temp file
DBEngine.CompactDatabase strTempPath, strNewPath
'delete the tempfile
Kill strTempPath
End FunctionNo additional references should be needed
lytell
May 08, 2021Copper Contributor
Seems to be looking for .MDB as opposed to .accdb in strTempPath