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
Nevermind I forgot to include the name of the DB. I think this worked it went from 18,560KB to 10,476KB
- isladogsMay 08, 2021MVPClearly it did work! I use that approach to compact a BE database from the FE but it can be used to compact any database. The code can also be used to compact the current database to a backup file. Try changing strOldPath to the path of the current database and see if it works for you as well
NOTE: A minor modification will allow it to compact password protected databases as well- lytellMay 30, 2021Copper ContributorGood news. I finally found the culprit - It was Bitdefender (free edition) after reading about a similar issue i decided to uninstall Bitdefender and Bam! all is good now.
- isladogsMay 30, 2021MVPGood to hear you have a solution. Thanks for letting us know the cause. It may help someone else in the future