国内最全IT社区平台 联系我们 | 收藏本站
华晨云阿里云优惠2
您当前位置:首页 > 数据库 > access > 恢复从 Access 2000、 Access 2002 或 Access 2003 中数据库删除

恢复从 Access 2000、 Access 2002 或 Access 2003 中数据库删除

来源:程序员人生   发布时间:2014-02-18 23:22:56 阅读次数:2406次
注意  本文示例代码使用 Microsoft 数据访问对象 为此代码才能正常运行 您必须引用 Microsoft DAO  对象库 可以进行 单击  工具  菜单中 VisualBasic 编辑器 上  引用  并确保选中  Microsoft DAO  对象库  复选框

    在 MicrosoftAccess 中打开数据库
    在数据库窗口 单击下 对象  模块  然后单击 新建 
    键入或粘贴以下代码 您只有创建模块中 

  复制代码 代码如下:

  Function RecoverDeletedTable() 
On Error GoTo ExitHere 

*Declarations* 
  Dim db As DAODatabase 
  Dim strTableName As String 
  Dim strSQL As String 
  Dim intCount As Integer 
  Dim blnRestored As Boolean 

*Init* 
  Set db = CurrentDb() 

*Procedure* 
  For intCount =  To dbTableDefsCount   
    strTableName = dbTableDefs(intCount)Name 
    If Left(strTableName ) = ~tmp Then 
      strSQL = SELECT DISTINCTROW [ & strTableName & ]* INTO  & Mid(strTableName ) &  FROM [ & strTableName & ]; 
      DoCmdSetWarnings False 
      DoCmdRunSQL strSQL 
      MsgBox A deleted table has been restored using the name  & Mid(strTableName ) &  vbOKOnly Restored 
      blnRestored = True 
    End If 
  Next intCount 

  If blnRestored = False Then 
MsgBox No recoverable tables found vbOKOnly 
  End If 

*EXIT/ERROR* 
ExitHere: 
  DoCmdSetWarnings True 
  Set db = Nothing 
  Exit Function 

ErrorHandler: 
  MsgBox ErrDescription 
  Resume ExitHere 

End Function



    在 调试 菜单上 单击 编译 数据库名称 数据库名称 
    保存为 RecoverTable 模块 要测试此函数 首先创建两个表 添加行 并删除这两个表
    在即时窗口 键入以下行 然后按 ENTER 键

RecoverDeletedTable
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠
程序员人生
------分隔线----------------------------
分享到:
------分隔线----------------------------
关闭
程序员人生