注意 : 本文示例代碼使用 Microsoft 數(shù)據(jù)訪問對象。 為此代碼才能正常運行, 您必須引用 Microsoft DAO 3.6 對象庫。 可以進行, 單擊 工具 菜單中 VisualBasic 編輯器, 上 引用 并確保選中 Microsoft DAO 3.6 對象庫 復選框。
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