Question : Compact and Repair on command

Hello Everyone,
I'm in the process of building a maintenance database that updates several other databases on a network. I was wondering how I would go about using code that would allow me to compact and repair databases that are closed. I'm hopping I  can have one button on a form that when pressed will run:
Code for compacting database 1 if Closed if not
Move on to compacting database 2

What is the best approach to do this?

Answer : Compact and Repair on command

You can also use the CompactRepair Method

Function RepairDatabase(strSource As String, _
        strDestination As String) As Boolean
        ' Input values: the paths and file names of
        ' the source and destination files.

    ' Trap for errors.
    On Error GoTo error_handler

    ' Compact and repair the database. Use the return value of
    ' the CompactRepair method to determine if the file was
    ' successfully compacted.
    RepairDatabase = _
        Application.CompactRepair( _
        LogFile:=True, _
        SourceFile:=strSource, _
        DestinationFile:=strDestination)

    ' Reset the error trap and exit the function.
    On Error GoTo 0
    Exit Function

' Return False if an error occurs.
error_handler:
    RepairDatabase = False

End Function
Random Solutions  
 
programming4us programming4us