compacting ms acess db

  • Thread starter Thread starter michael moore
  • Start date Start date
M

michael moore

does anyone know of a compacting tool that can be run from
the command line.

i need to be able to run compacts unattended.

thanks
 
This isn't from the command line but you can put in an
access db and have it launch when the db is opened and use
Windows task scheduler(or something similar) to launch it.
I use it and it lets me compact multiple db's any time I
schedule. I got this from Josh a while back.



Function Compact(stDataFile as String) as Boolean

'This function will backup and compact the mdb file given
by the stDataFile
path.
'Manually backup and test debug it first!

Dim stOutFile as String, stBackUpFile as String

stOutFile = Left$(stDataFile, Len(stDataFile) - 4) & ".CMP"

DoCmd.SetWarnings False
DoCmd.Hourglass True

'Delete Temporary OutputFile if exists
On Error Resume Next
Kill stOutFile
On Error Goto Err_Function

'Backup
stBackUpFile = Left(stDataFile, Len(stDataFile) - 4) &
".BAK"
On Error Resume Next
Kill stBackUpFile
On Error Goto Err_Function
FileCopy stDataFile, stBackUpFile

'Compact
DBEngine.CompactDatabase stDataFile, stOutFile,
DB_LANG_GENERAL

'Delete Uncompacted Version
Kill stDataFile

'Rename Compacted Version
Name stOutFile As stDataFile

Compact = True

Exit_Function:
DoCmd.SetWarnings True
DoCmd.Hourglass False
Exit Function

Err_Function:
Compact = False
msgbox err.description
Resume Exit_Function
End Function


Jim
 
Back
Top