这是小七的例子:
Function RepDB(strDBPathName As String)
On Error GoTo err_RepDB
dbengine.RepairDatabase strDBPathName
RepDB = "ass"
Exit Function
err_RepDB:
Select Case Err.Number
Case 3356
MsgBox Err.Description & vbLf & _
"准备修复的数据库处于打开状态,请关闭所有操作后重试!"
Case Else
MsgBox Err.Description
End Select
RepDB = CVErr(65535)
End Function
这是KOMAZ的例子:
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