You can do it in code, to another database, but not to the currently open database.
' This code was originally written by Terry Wickenden.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
Sub CompactDB(strOldDb As String, Optional strNewDb As String)
'strOldDb = name of database to be compacted including full path
'strNewDb = name of database once compacted including full path
Dim strCompact As String
On Error GoTo errCompactDB
'Turn off screen refresh
Application.Echo False
'Check if new database has been specified
If IsMissing(strNewDb) Then
strCompact = strOldDb
Else
strCompact = strNewDb
End If
'Which data base to be compacted
SendKeys strOldDb, False
SendKeys "{enter}", False
'Name of database to compact to
SendKeys strCompact, False
SendKeys "{enter}", False
RunCommand acCmdCompactDatabase
exitCompactDB:
'Turn the screen refresh back on
Application.Echo True
Exit Sub
errCompactDB:
Select Case Err
Case 2501
'Cancel Button selected in the compact database dialog
Case Else
MsgBox Err.Number & ":- " & vbCrLf & Err.Description
End Select
Resume exitCompactDB
End Sub
' This code was originally written by Terry Wickenden.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
Sub DBRepair(strRepair As String)
On Error GoTo errDBRepair
SendKeys strRepair
SendKeys "{ENTER}"
RunCommand acCmdRepairDatabase
Exit Sub
errDBRepair:
Select Case Err
Case 2501
'Cancel Button selected in the repair database dialog
Case Else
MsgBox Err.Number & ":- " & vbCrLf & Err.Description
End Select
End Sub
I got all of the code from
, there might be a better way to do it.
HTH!
-Brad