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.
Before we launch off on a complicated DAO solution, it's always worth the effort to try a simple Ctl-Z undo command. This process will only work if you haven't performed some other Cut, Copy Paste Undo combination of actions before trying to restore the table. All the same, there's no extra charge for attempting the Undo, so give it a whirl. If that fails, then you need to write code.
'As I stated in the introduction, there are some limits as
'to what may be restored ... and when. Here's the exception list:
'The database has not been closed since the deletion of the table
'The database has not been compacted since the deletion of the table
'The table was deleted using the Microsoft Access user interface
' *************** BEGIN CODE HERE *********************************
' This code was previously posted at Comp.Databases.MS-Access by a
' kind soul some years ago. I forgot to record that person's name so
' I am unable to give credit where it is due :-(
'
' It seems to have been adapted from the Knowledge Base Article Q179161.
'
' This module contains simple Visual Basic for Applications function
' that you can use to recover a table deleted from a Microsoft Access
' for Windows 95 and Microsoft Access 97 database under the following
' conditions:
'
' - The database has not been closed since the deletion of the table.
' - The database has not been compacted since the deletion of the table.
' - The table was deleted using the Microsoft Access user interface.
'
' NOTE: If multiple tables have inadvertently been deleted, this function
' recovers only the last table that was deleted. The other tables are lost.
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
' **************** END CODE HERE **********************************