当前位置: 首页 > 图文教程 > 数据库 > Access > 恢复从 Access 2000、 Access 2002 或 Access 2003 中数据库删除表的方法

Access
多表查询技巧
用 INNER JOIN语法联接多个表建记录集
union这个连接是有什么用的和INNER JOIN有什么区别
Microsoft Access 数据库常规规格
随机提取N条记录
给你的数据库文件减肥
将Access数据库移植到SQL Server
Access使用查询--1.2.用选择查询进行分组数据的计算
Access使用宏控制程序
Access使用宏控制程序 3.在宏中使用条件
Access使用宏控制程序 4.常用的宏操作
Access使用宏控制程序--1.5.一个宏的实例——检验口令
Access使用宏控制程序--1.6.使用宏的几点说明
Access使用查询--1.1. 用选择查询建立计算字段
Access使用查询
使用准则进行条件查询
Access使用查询 在查询中执行计算的注意事项
使用准则进行条件查询--1.3.运行查询前输入参数
建立自由的会计日期的报表--1.3.根据用户选择日期自动计算期初期末日期
建立自由的会计日期的报表--1.4.让报表处理期初和期末之间的数据

恢复从 Access 2000、 Access 2002 或 Access 2003 中数据库删除表的方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 114 ::
收藏到网摘: n/a

注意 : 本文示例代码使用 Microsoft 数据访问对象。 为此代码才能正常运行, 您必须引用 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