文章詳情頁(yè)
恢復(fù)從 Access 2000、 Access 2002 或 Access 2003 中數(shù)據(jù)庫(kù)刪除表的方法
瀏覽:206日期:2023-03-18 16:41:51
注意 : 本文示例代碼使用 Microsoft 數(shù)據(jù)訪(fǎng)問(wèn)對(duì)象。 為此代碼才能正常運(yùn)行, 您必須引用 Microsoft DAO 3.6 對(duì)象庫(kù)。 可以進(jìn)行, 單擊 工具 菜單中 VisualBasic 編輯器, 上 引用 并確保選中 Microsoft DAO 3.6 對(duì)象庫(kù) 復(fù)選框。
1. 在 MicrosoftAccess 中打開(kāi)數(shù)據(jù)庫(kù)。
2. 在數(shù)據(jù)庫(kù)窗口, 單擊下 對(duì)象 , 模塊 , 然后單擊 新建 。
3. 鍵入或粘貼以下代碼, 您只有創(chuàng)建模塊中:
復(fù)制代碼 代碼如下:
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. 在 調(diào)試 菜單上, 單擊 編譯 數(shù)據(jù)庫(kù)名稱(chēng) 數(shù)據(jù)庫(kù)名稱(chēng) 。
5. 保存為 RecoverTable 模塊。 要測(cè)試此函數(shù), 首先創(chuàng)建兩個(gè)表, 添加行, 并刪除這兩個(gè)表。
6. 在即時(shí)窗口, 鍵入以下行, 然后按 ENTER 鍵:
RecoverDeletedTable
1. 在 MicrosoftAccess 中打開(kāi)數(shù)據(jù)庫(kù)。
2. 在數(shù)據(jù)庫(kù)窗口, 單擊下 對(duì)象 , 模塊 , 然后單擊 新建 。
3. 鍵入或粘貼以下代碼, 您只有創(chuàng)建模塊中:
復(fù)制代碼 代碼如下:
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. 在 調(diào)試 菜單上, 單擊 編譯 數(shù)據(jù)庫(kù)名稱(chēng) 數(shù)據(jù)庫(kù)名稱(chēng) 。
5. 保存為 RecoverTable 模塊。 要測(cè)試此函數(shù), 首先創(chuàng)建兩個(gè)表, 添加行, 并刪除這兩個(gè)表。
6. 在即時(shí)窗口, 鍵入以下行, 然后按 ENTER 鍵:
RecoverDeletedTable
標(biāo)簽:
Access
上一條:ACCESS的參數(shù)化查詢(xún),附VBSCRIPT(ASP)和C#(ASP.NET)函數(shù)第1/2頁(yè)下一條:access下如何恢復(fù)已經(jīng)刪除的記錄;如何恢復(fù)已經(jīng)刪除的表、窗體等等對(duì)象
相關(guān)文章:
1. Microsoft Office Access隱藏和顯示字段的方法2. Microsoft Office Access刪除字段的方法3. Access中批量替換數(shù)據(jù)庫(kù)內(nèi)容的兩種方法4. Microsoft Office Access添加圖片的方法5. Microsoft Office Access創(chuàng)建窗體的方法6. ACCESS的參數(shù)化查詢(xún),附VBSCRIPT(ASP)和C#(ASP.NET)函數(shù)第1/2頁(yè)7. 使用 Database Access(數(shù)據(jù)庫(kù)訪(fǎng)問(wèn))組件8. ACCESS 調(diào)用后臺(tái)存儲(chǔ)過(guò)程的實(shí)現(xiàn)方法9. Access連接數(shù)據(jù)源(ODBC)配置(新手必知)10. Access轉(zhuǎn)Sql Server問(wèn)題 實(shí)例說(shuō)明
排行榜
