SoFunction
Updated on 2025-04-08

How to restore the method to delete tables from databases in Access 2000, Access 2002, or Access 2003


Function RecoverDeletedTable() 
On Error GoTo ExitHere 

'*Declarations* 
  Dim db As  
  Dim strTableName As String 
  Dim strSQL As String 
  Dim intCount As Integer 
  Dim blnRestored As Boolean 

'*Init* 
  Set db = CurrentDb() 

'*Procedure* 
  For intCount = 0 To  - 1 
    strTableName = (intCount).Name 
    If Left(strTableName, 4) = "~tmp" Then 
      strSQL = "SELECT DISTINCTROW [" & strTableName & "].* INTO " & Mid(strTableName, 5) & " FROM [" & strTableName & "];" 
       False 
       strSQL 
      MsgBox "A deleted table has been restored, using the name '" & Mid(strTableName, 5) & "'", vbOKOnly, "Restored" 
      blnRestored = True 
    End If 
  Next intCount 

  If blnRestored = False Then 
MsgBox "No recoverable tables found", vbOKOnly 
  End If 

'*EXIT/ERROR* 
ExitHere: 
   True 
  Set db = Nothing 
  Exit Function 

ErrorHandler: 
  MsgBox  
  Resume ExitHere 

End Function