UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> UndeleteTables    

This information was pulled form a forum post here. Quote from the post:

you CAN undelete a table that has been deleted through the UI -- as long as the database file that contained that table has not had a Compact and Repair operation performed on it. You see, when a table is deleted through the Navigation Pane, it is merely renamed with a "~TMP" prefix and its marked as hidden (and that means really hidden). So, if you DON'T C/R you can find tables that match that criteria (dbHiddenObject and name beginning with "~TMP"), you can simply unmark the table as being hidden and rename the object. ( - datAdrenaline)

Public Sub UndeleteTables()
   Dim tdf As DAO.TableDef, fld As DAO.Field2
   Dim strName As String, strFields As String
   With CurrentDb
'       Loop through all of the tables
       For Each tdf In .TableDefs
'           If it looks like a deleted table...
           If ((tdf.Attributes And dbHiddenObject) <> 0) And (tdf.Name Like "~TMP*") Then
'               Try to extract the name of table from the NameMap property, if possible
               On Error Resume Next
               strName = Split(Mid(tdf.Properties("NameMap"), 23), vbNullChar)(0)
               If Err <> 0 Then Err.Clear

'               if that didn't work, make up a random name.
               If Len(strName) = 0 Then strName = "xTable_" & Int(Timer)
               On Error GoTo 0
'               Make a comma-separated list of the field names in the table.
               For Each fld In tdf.Fields
                   strFields = strFields & ", " & fld.Name
               Next fld
               If strFields <> "" Then strFields = Mid(strFields, Len(", ") + 1)
'               Ask the user if they want to undelete this table
               strName = InputBox("Fields: " & strFields, _
                                   "Please provide name to undelete the table.", strName)
'               If the user doesn't hit cancel...
               If strName <> "" Then
'                   Undelete the table
                   tdf.Attributes = tdf.Attributes And Not dbHiddenObject
                   tdf.Name = strName
               End If
           End If
       Next tdf
   End With
End Sub

Creative Commons License
UndeleteTables by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search

Thank you for your support!
This page has been accessed 5,393 times.  This page was last modified 19:47, 16 May 2014 by doctor9. Contributions by Brent Spaulding and Jack Leach  Disclaimers