Share via


Application.CompactRepair Method (Access)

Compacts and repairs the specified database or Microsoft Access project (.adp) file. Returns a Boolean; True if the process was successful.

Syntax

.CompactRepair(SourceFile, DestinationFile, LogFile)

A variable that represents an Application object.

Parameters

Name

Required/Optional

Data Type

Description

SourceFile

필수

String

The full path and filename of the database or project file to compact and repair.

DestinationFile

필수

String

The full path and filename for where the recovered file will be saved.

LogFile

선택

Boolean

True if a log file is created in the destination directory to record any corruption detected in the source file. A log file is only created if corruption is detected in the source file. If LogFile is False or omitted, no log file is created, even if corruption is detected in the source file.

Return Value

Boolean

Remarks

The source file must not be the current database or be open by any other user, since calling this method will open the file exclusively.

Link provided by:커뮤니티 구성원 아이콘 The UtterAccess community | About the Contributors

Example

The following example compacts and repairs a database, creates a log if there's any corruption in the source file, and returns a Boolean value based on whether the recovery was successful. For the example to work, you must pass it the paths and file names of the source and destination files.

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 

About the Contributors

UtterAccess(영문일 수 있음)는 Microsoft Access 위키 및 도움말 포럼입니다. 가입하려면 여기를 클릭하십시오(영문일 수 있음).

참고 항목

개념

Application Object

Application Object Members