Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Public Sub CompactDB(strDBName As String)
On Error GoTo CompactDB_Err
Dim strDBNameRoot as String
Dim strTempDBName As String
Dim strDBBakName As String
'check to see if DB exists
If Dir(strDBName) = "" Then
Exit Sub
End If
'remove .mdb extension to get root of the file name
If Right(strDBName, 4) = ".mdb" Then
strDBNameRoot = LStrip(strDBName, 4)
'LStrip = Left(strDBName, Len(strDBName) - 4)
'For some reason I make a lot of typos writing this
' so I created a function for it.
Else
strDBNameRoot = strDBName
End If
'set up file names for temp and backup files
strTempDBName = strDBNameRoot & "_c.mdb"
strDBBakName = strDBNameRoot & ".bak"
'remove previous temp file
If Dir(strTempDBName) <> "" Then
Kill strTempDBName
End If
'compact the database
DBEngine.CompactDatabase strDBName, strTempDBName
'remove the previous backup file
'this only happens if the compact succeeded
If Dir(strDBBakName) <> "" Then
Kill strDBBakName
End If
'rename files to move the old database file into backup filename
' and the temp file into the database filename
Name strDBName As strDBBakName
Name strTempDBName As strDBName
Exit_CompactDB:
Exit Sub
CompactDB_Err:
If Err.Number = 3356 Then
'I forgot what this error was, but intentionally ignored it
Else
StdErrMsg Err.Number, Err.Description
'My standard error message routine
End If
Resume Exit_CompactDB