Full Version: Compact and Repair by code.
UtterAccess Discussion Forums > Microsoft® Access > Access Modules
Silence
Hi.

Is there any way that I can compact and repair the database using code, that way the user doesn't have to worry about doing it themselves.
battroid
Hi there,

took this from the MS-Access2002 docs

CODE
  
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


I think it works with 2000, too.

Have fun
Norman
ChrisLeClark
Hi
Another alternative for you....

Here is a download from Candace Tripp's website.

You may be able to use it instead or check the background code to add to your own database.

hth
Chris
tomhendrickx
Tehere are also ex. in the UA Archive.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.