Function RepairCompact (strDatabase As String) As Integer ' 'NOTE: This procedure contains line break characters 'for readability. These characters are not supported 'in Access Basic. ' ' 'This function repairs databases. It is recommended to compact 'them afterwards. Automating the compacting of databases 'seems a bit risky but here we are: ' Dim strTempFile As String, varReturn As Variant
On Error GoTo RepairCompact_Err
varReturn = SysCmd(SYSCMD_SETSTATUS, "Looking for " _
& strDatabase & "...")
If Mid$(strDatabase, InStr(strDatabase, "."), 4) = ".MDB" Then
strTempFile = strDatabase
Mid$(strTempFile, InStr(strTempFile, "."), 4) = ".NEW"
Else
MsgBox "Can't handle the filename of this file.", 64,_
"Application Services"
varReturn = SysCmd(SYSCMD_CLEARSTATUS)
GoTo RepairCompact_Exit
End If
varReturn = SysCmd(SYSCMD_SETSTATUS, "Repairing " & _
strDatabase & "...")
DBEngine.RepairDatabase strDatabase
varReturn = SysCmd(SYSCMD_SETSTATUS, "Compacting " & _
strDatabase & "...")
DBEngine.CompactDatabase strDatabase, strTempFile
'
'Here's the risky but necessary part:
'
Kill strDatabase: Name strTempFile As strDatabase
varReturn = SysCmd(SYSCMD_CLEARSTATUS)
RepairCompact = True
RepairCompact_Exit:
Exit Function
RepairCompact_Err: Select Case Err Case Else MsgBox Err & ": " & Error$(Err), 16, _ "RepairCompact Error" m_varReturn = SysCmd(SYSCMD_SETSTATUS, Error$(Err)) RepairCompact = False GoTo RepairCompact_Exit End Select End Function