濮阳杆衣贸易有限公司

主頁 > 知識庫 > access下如何恢復已經(jīng)刪除的記錄;如何恢復已經(jīng)刪除的表、窗體等等對象

access下如何恢復已經(jīng)刪除的記錄;如何恢復已經(jīng)刪除的表、窗體等等對象

熱門標簽:400電話申請怎么看 江西南昌百應電話機器人 杭州400電話如何申請的 隨州營銷電話機器人怎么樣 高德地圖標注商家在哪 天音通信電話機器人 機器人電話機創(chuàng)意繪畫 400電話從哪里申請濱州 hbuilder地圖標注
問題:

    如何恢復已經(jīng)刪除的記錄;如何恢復已經(jīng)刪除的表、窗體等等對象
1、我用 DELETE FROM TABLE 刪除了一些記錄,現(xiàn)在發(fā)現(xiàn)誤刪除了,該如何恢復?
2、我直接手動刪除或者用 DROP TABLE 刪除了一個表,現(xiàn)在發(fā)現(xiàn)是誤刪除了,該如何恢復?
3、我手動刪除了一個窗體,該如何恢復?
4、我刪除了記錄,可是數(shù)據(jù)庫體積并沒有減小,那么是否能找回記錄呢?

 


回答:

    1、已經(jīng)刪除的記錄是無法恢復的,ACCESS 不是 FOXPRO,MDB 格式不是 DBF 格式,沒有邏輯刪除和物理刪除的概念,一旦刪除就無法恢復了。
2、無法恢復,但是你可以查看一下,有沒有隱藏的以 "~" 符號開頭的表,更改該表的名稱有可能找回你需要的表。
3、無法恢復,但是你可以查看一下有沒有系統(tǒng)隱藏的對象,有時候對象被刪除時系統(tǒng)并不直接刪除,而是更改對象名后隱藏它。
4、數(shù)據(jù)庫體積的確沒有變小,你壓縮修復數(shù)據(jù)庫后體積就會變小了。那是因為在二進制上你的數(shù)據(jù)的確沒有被刪除,仍然存放在磁盤的某個扇區(qū),但是微軟沒有提供 MDB 格式二進制組織方式的參考資料(微軟也不會提供,其他第三方公司也沒有權利直接反編譯 MDB 格式)。至今為止,中國大陸我也沒有看到過相關的參考資料。所以目前為止,你已經(jīng)刪除的數(shù)據(jù)是無法恢復的。但是你可以嘗試使用磁盤恢復軟件來找到恢復數(shù)據(jù)的方法,但是該方法不在本文討論范圍。

建議:在建立數(shù)據(jù)庫結構時,可以在各個表中再多加一個 ISDEL 字段,刪除記錄時不使用 DELETE FROM ,而使用 UPDATE TABLE SET ISDEL=TRUE 這樣的語句,然后在界面上不顯示 ISDEL=TRUE 的記錄即可。
復制代碼 代碼如下:

如果還沒有被壓縮理論上可以。試試這段代碼吧。加在access模組中
恢復刪除的工作表(未被壓縮)
 
Public Function FnUndeleteObjects() As Boolean
  On Error GoTo ErrorHandler:
  Dim strObjectName           As String
  Dim rsTables                As DAO.Recordset
  Dim dbsDatabase             As DAO.Database
  Dim tDef                    As DAO.TableDef
  Dim qDef                    As DAO.QueryDef
  Dim intNumDeletedItemsFound As Integer
  Set dbsDatabase = CurrentDb
  For Each tDef In dbsDatabase.TableDefs
      'This is actually used as a 'Deleted Flag'
      If tDef.Attributes And dbHiddenObject Then
         strObjectName = FnGetDeletedTableNameByProp(tDef.Name)
         strObjectName = InputBox("A deleted TABLE has been found."  _
                         vbCrLf  vbCrLf  _
                         "To undelete this object, enter a new name:", _
                         "Access Undelete Table", strObjectName)

         If Len(strObjectName) > 0 Then
            FnUndeleteTable CurrentDb, tDef.Name, strObjectName
         End If
         intNumDeletedItemsFound = intNumDeletedItemsFound + 1
      End If
  Next tDef

  For Each qDef In dbsDatabase.QueryDefs
      'Note 'Attributes' flag is not exposed for QueryDef objects,
      'We could look up the flag by using MSysObjects but
      'new queries don't get written to MSysObjects until
      'Access is closed. Therefore we'll just check the
      'start of the name is '~TMPCLP' ...
      If InStr(1, qDef.Name, "~TMPCLP") = 1 Then
         strObjectName = ""
         strObjectName = InputBox("A deleted QUERY has been found."  _
                         vbCrLf  vbCrLf  _
                         "To undelete this object, enter a new name:", _
                         "Access Undelete Query", strObjectName)

         If Len(strObjectName) > 0 Then
            If FnUndeleteQuery(CurrentDb, qDef.Name, strObjectName) Then
               'We'll rename the deleted object since we've made a
               'copy and won't be needing to re-undelete it.
               '(To break the condition "~TMPCLP" in future...)
                qDef.Name = "~TMPCLQ"  Right$(qDef.Name, Len(qDef.Name) - 7)
             End If
         End If
         intNumDeletedItemsFound = intNumDeletedItemsFound + 1
      End If
  Next qDef
  If intNumDeletedItemsFound = 0 Then
     MsgBox "Unable to find any deleted tables/queries to undelete!"
  End If

  Set dbsDatabase = Nothing
  FnUndeleteObjects = True
ExitFunction:
  Exit Function
ErrorHandler:
  MsgBox "Error occured in FnUndeleteObjects() - "  _
         Err.Description  " ("  CStr(Err.Number)  ")"
  GoTo ExitFunction
End Function


Private Function FnUndeleteTable(dbDatabase As DAO.Database, _
                 strDeletedTableName As String, _
                 strNewTableName As String)

  'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
  'Written 18/04/2005
  Dim tDef As DAO.TableDef
  Set tDef = dbDatabase.TableDefs(strDeletedTableName)
  'Remove the Deleted Flag...
  tDef.Attributes = tDef.Attributes And Not dbHiddenObject
  'Rename the deleted object to the original or new name...
  tDef.Name = strNewTableName
  dbDatabase.TableDefs.Refresh
  Application.RefreshDatabaseWindow
  Set tDef = Nothing
End Function

Private Function FnUndeleteQuery(dbDatabase As DAO.Database, _
                 strDeletedQueryName As String, _
                 strNewQueryName As String)

  'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
  'Written 18/04/2005
  'We can't just remove the Deleted flag on queries
  '('Attributes' is not an exposed property)
  'So instead we create a new query with the SQL...

  'Note: Can't use DoCmd.CopyObject as it copies the dbHiddenObject attribute!

  If FnCopyQuery(dbDatabase, strDeletedQueryName, strNewQueryName) Then
     FnUndeleteQuery = True
     Application.RefreshDatabaseWindow
  End If
End Function


Private Function FnCopyQuery(dbDatabase As DAO.Database, _
                 strSourceName As String, _
                 strDestinationName As String)

  'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
  'Written 18/04/2005
  On Error GoTo ErrorHandler:

  Dim qDefOld As DAO.QueryDef
  Dim qDefNew As DAO.QueryDef
  Dim Field As DAO.Field

  Set qDefOld = dbDatabase.QueryDefs(strSourceName)
  Set qDefNew = dbDatabase.CreateQueryDef(strDestinationName, qDefOld.SQL)

  'Copy root query properties...
  FnCopyLvProperties qDefNew, qDefOld.Properties, qDefNew.Properties

  For Each Field In qDefOld.Fields
      'Copy each fields individual properties...
      FnCopyLvProperties qDefNew.Fields(Field.Name), _
                         Field.Properties, _
                         qDefNew.Fields(Field.Name).Properties
  Next Field
  dbDatabase.QueryDefs.Refresh
  FnCopyQuery = True
ExitFunction:
  Set qDefNew = Nothing
  Set qDefOld = Nothing
  Exit Function
ErrorHandler:
  MsgBox "Error re-creating query '"  strDestinationName  "':"  vbCrLf  _
         Err.Description  " ("  CStr(Err.Number)  ")"
  GoTo ExitFunction
End Function

Private Function PropExists(Props As DAO.Properties, strPropName As String) As Boolean
  'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
  'Written 18/04/2005
  'If properties fail to be created, we'll just ignore the errors
  On Error Resume Next
  Dim Prop As DAO.Property
  For Each Prop In Props
      If Prop.Name = strPropName Then
         PropExists = True
         Exit Function ' Short circuit
      End If
  Next Prop
  PropExists = False
End Function

Private Sub FnCopyLvProperties(objObject As Object, OldProps As DAO.Properties, NewProps As DAO.Properties)
  'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
  'Written 18/04/2005
  'If properties fail to be created, we'll just ignore the errors
  On Error Resume Next
  Dim Prop As DAO.Property
  Dim NewProp As DAO.Property
  For Each Prop In OldProps
      If Not PropExists(NewProps, Prop.Name) Then
         If IsNumeric(Prop.Value) Then
            NewProps.Append objObject.CreateProperty(Prop.Name, Prop.Type, CLng(Prop.Value))
         Else
            NewProps.Append objObject.CreateProperty(Prop.Name, Prop.Type, Prop.Value)
         End If
      Else
         With NewProps(Prop.Name)
              .Type = Prop.Type
              .Value = Prop.Value
         End With
      End If
  Next Prop
End Sub

Private Function FnGetDeletedTableNameByProp(strRealTableName As String) As String
  'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
  'Written 18/04/2005
  'If an error occurs here, just ignore (user will override the blank name)
  On Error Resume Next
  Dim i As Long
  Dim strNameMap As String

  'Look up the Unicode translation NameMap property to try to guess the
  'original table name... (Access 2000+ only - and doesn't always exist?!)

  strNameMap = CurrentDb.TableDefs(strRealTableName).Properties("NameMap")
  strNameMap = Mid(strNameMap, 23) 'Offset of the table name...

  'Find the null terminator...
  i = 1
  If Len(strNameMap) > 0 Then
     While (i  Len(strNameMap)) And (Asc(Mid(strNameMap, i)) > 0)
       i = i + 1
     Wend
  End If
  FnGetDeletedTableNameByProp = Left(strNameMap, i - 1)
End Function

標簽:保定 葫蘆島 招商 沈陽 常德 鶴崗 昆明 石嘴山

巨人網(wǎng)絡通訊聲明:本文標題《access下如何恢復已經(jīng)刪除的記錄;如何恢復已經(jīng)刪除的表、窗體等等對象》,本文關鍵詞  access,下,如何,恢復,已經(jīng),;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《access下如何恢復已經(jīng)刪除的記錄;如何恢復已經(jīng)刪除的表、窗體等等對象》相關的同類信息!
  • 本頁收集關于access下如何恢復已經(jīng)刪除的記錄;如何恢復已經(jīng)刪除的表、窗體等等對象的相關信息資訊供網(wǎng)民參考!
  • 推薦文章
    泸定县| 海盐县| 泗水县| 曲松县| 兴文县| 凤凰县| 二手房| 合阳县| 定南县| 花莲县| 浦江县| 太白县| 准格尔旗| 岳阳县| 罗平县| 红桥区| 扬中市| 高州市| 沐川县| 金昌市| 谢通门县| 贵德县| 和田县| 阿合奇县| 萨迦县| 墨玉县| 白水县| 宾阳县| 卓资县| 和田市| 滨州市| 西丰县| 石嘴山市| 武定县| 乌拉特前旗| SHOW| 红安县| 洪雅县| 凯里市| 大姚县| 会泽县|