This example can be used to compact a database. It can not be used to compact the database that is calling it.
'***************** Code Start ******************* '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
Return to Example List