compacting ms acess db

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
 
J

Jim/Chris

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top