壓縮和修復(fù)指定的數(shù)據(jù)庫 (.mdb) 或 Microsoft Access 項目 (.adp) 文件。返回 Boolean 型值;如果處理成功,返回 True。
expression.CompactRepair(SourceFile, DestinationFile, LogFile)
expression 必需。返回“應(yīng)用于”列表中的一個對象的表達(dá)式。
SourceFile String 型,必需。代表要壓縮和修復(fù)的數(shù)據(jù)庫或項目文件的完整路徑和文件名。
DestinationFile String 型,必需。完整的路徑和文件名,代表所返回文件的保存位置。
LogFile Boolean 型,可選。如果在目標(biāo)目錄中創(chuàng)建一個日志文件用于記錄在源文件中檢測到的損壞,則為 True。只有在源文件中檢測到損壞時,才創(chuàng)建日志文件。如果 LogFile 為 False 或省略,就不創(chuàng)建日志文件,即使在源文件中檢測到損壞也是如此。
源文件不可以是當(dāng)前數(shù)據(jù)庫,也不能被其他用戶打開,因為調(diào)用該方法將會以獨占方式打開源文件。
下面的示例將壓縮和修復(fù)一個數(shù)據(jù)庫,如果在源文件中檢測到損壞,則會創(chuàng)建一個日志文件,并根據(jù)恢復(fù)是否成功而返回一個 Boolean 值。為使該示例運行,必須將源文件和目標(biāo)文件的路徑和文件名傳給它。
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