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