Function UnDeleteTable(Optional sName As String)
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim sTable As String
Dim sSQL As String
Dim sMsg As String
If IsMissing(sName) Then sName = "RestoredTable"
If Len(sName) = 0 Then sName = "RestoredTable"
Set db = CurrentDb()
For Each tdf In db.TableDefs
If Left(tdf.Name, 4) = "~tmp" Then
sTable = tdf.Name
sSQL = "SELECT [" & sTable & "].* INTO " & sName
sSQL = sSQL & " FROM [" & sTable & "];"
db.Execute sSQL
sMsg = "A deleted table has been restored as " & sName
MsgBox sMsg, vbOKOnly, "Restored"
GoTo Exit_Undelete
End If
Next
' If the code has fallen to this point, then no deleted
' tables exist in the catalog and none are recoverable.
MsgBox "No Recoverable Tables Found", vbOKOnly, "Not Found"
Exit_Undelete:
Set db = Nothing
Exit Function
Err_Undelete:
MsgBox Err.Description
Resume Exit_Undelete
End Function