恢複從Access資料庫刪除表的方法

來源:互聯網
上載者:User

   注意 : 本文範例程式碼使用 Microsoft Data Access Objects。 為此代碼才能正常運行, 您必須引用 Microsoft DAO 3.6 物件程式庫。 可以進行, 單擊 工具 菜單中 VisualBasic 編輯器, 上 引用 並確保選中 Microsoft DAO 3.6 物件程式庫 複選框。

  1. 在 MicrosoftAccess 中開啟資料庫。

  2. 在資料庫視窗, 單擊下 對象 , 模組 , 然後單擊 建立 。

  3. 鍵入或粘貼以下代碼, 您只有建立模組中:

  複製代碼 代碼如下:

  Function RecoverDeletedTable()

  On Error GoTo ExitHere

  '*Declarations*

  Dim db As DAO.Database

  Dim strTableName As String

  Dim strSQL As String

  Dim intCount As Integer

  Dim blnRestored As Boolean

  '*Init*

  Set db = CurrentDb()

  '*Procedure*

  For intCount = 0 To db.TableDefs.Count - 1

  strTableName = db.TableDefs(intCount).Name

  If Left(strTableName, 4) = "~tmp" Then

  strSQL = "SELECT DISTINCTROW [" & strTableName & "].* INTO " & Mid(strTableName, 5) & " FROM [" & strTableName & "];"

  DoCmd.SetWarnings False

  DoCmd.RunSQL strSQL

  MsgBox "A deleted table has been restored, using the name '" & Mid(strTableName, 5) & "'", vbOKOnly, "Restored"

  blnRestored = True

  End If

  Next intCount

  If blnRestored = False Then

  MsgBox "No recoverable tables found", vbOKOnly

  End If

  '*EXIT/ERROR*

  ExitHere:

  DoCmd.SetWarnings True

  Set db = Nothing

  Exit Function

  ErrorHandler:

  MsgBox Err.Description

  Resume ExitHere

  End Function

  4. 在 調試 菜單上, 單擊 編譯 資料庫名稱 資料庫名稱 。

  5. 儲存為 RecoverTable 模組。 要測試此函數, 首先建立兩個表, 添加行, 並刪除這兩個表。

  6. 在即時視窗, 鍵入以下行, 然後按 ENTER 鍵:

  RecoverDeletedTable

        注:更多精彩教程請關注三聯設計教程 欄目,

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.