Access SS said:
I deleted a table out of my database... i know need it back. I still have
the database open, is there anyway to get the table back?
If you haven't compacted or done anything else, this might work:
'------ start of code ------
Function UndeleteTable()
Dim db As DAO.Database, strTableName As String
Dim i As Integer, StrSqlString As String
Set db = CurrentDb()
For i = 0 To db.TableDefs.Count - 1
If Left(db.TableDefs(i).Name, 4) = "~tmp" Then
strTableName = db.TableDefs(i).Name
StrSqlString = "SELECT DISTINCTROW [" & strTableName & _
"].* INTO MyUndeletedTable FROM [" & strTableName & "];"
DoCmd.SetWarnings False
DoCmd.RunSQL StrSqlString
DoCmd.SetWarnings True
MsgBox "A table has been restored as MyUndeletedTable", _
vbOKOnly, "Restored"
GoTo Exit_UndeleteTable
End If
Next i
MsgBox "No Recoverable Tables Found", vbOKOnly, "Not Found"
Exit_UndeleteTable:
Set db = Nothing
Exit Function
Err_UndeleteTable:
MsgBox Err.Description
Resume Exit_UndeleteTable
End Function
'------ end of code ------
You would paste that code into a standard module, and then either invoke it
via F5 or enter this in the Immediate Window:
UndeleteTable