恢复从 access 2000、 access 2002 或 access 2003 中数据库删除表的方法
注意 : 本文示例代码使用 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