Public Function fCompactBE(TblName As String) As Boolean ' attemps to compact db TblName linked to, ' if successful returns true otherwise returns false Dim strPath As String, strDB As String, strName As String, strDBTmp As String fCompactBE = False 'default to fail On Error GoTo FastEx 'just ignore next few possible errors strPath = CurrentDb.TableDefs(TblName).Connect strDB = Mid(strPath, InStr(1, strPath, "=") + 1) 'get rid of beginning strName = Dir(strDB) 'get file name If strName = "" Then Exit Function 'no file, could be compacting by another strPath = Left(strDB, Len(strDB) - Len(strName)) 'get just the path strDBTmp = strPath & Left(strName, Len(strName) - 4) + "_tmp.mdb" 'create temp file name Name strDB As strDBTmp 'rename db to temp file On Error GoTo CompactErr 'trap if compact fails DBEngine.CompactDatabase strDBTmp, strDB 'compact db On Error Resume Next 'ignore failer to delete temp file Kill strDBTmp 'delete temp file fCompactBE = True 'show success Exit Function 'exit & leave temp file CompactErr: 'compact failed Name strDBTmp As strDB 'rename DB back to true name FastEx: End Function