恢复从数据库中删除的表-崔宇
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access数据库-表


恢复从数据库中删除的表

发表时间:2020/3/13 19:14:24 评论(0) 浏览(4038)  评论 | 加入收藏 | 复制
   
摘 要:恢复从数据库中删除的表
正 文:

如何创建一个示例 Visual Basic for Applications (VBA) 函数, 在以下情况下, 您可以使用它来恢复从 Access 数据库中删除的表:

  • 自删除表以来,数据库尚未关闭。

  • 自删除表以来,数据库尚未被压缩。

  • 使用 Access 用户界面删除了表。

  • 表不包含任何多值字段或附件字段。


Sub RecoverDeletedTable() 
On Error GoTo ExitHere 
 
 Dim db As DAO.Database 
 Dim strTableName As String 
 Dim strSQL As String 
 Dim intCount As Integer 
 Dim blnRestored As Boolean 
 
 Set db = CurrentDb() 
 
 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 Sub 
 
ErrorHandler: 
 MsgBox Err.Description 
 Resume ExitHere 
 
End Sub


Access软件网交流QQ群(群号:198465573)
 
 相关文章
在数据库中恢复误删除表示例  【十段  2008/5/30】
恢复删除的表  【十段  2008/6/2】
恢复被删除表的另外一种方法  【叶海峰  2009/7/23】
Access恢复被删除的表和查询的函数  【Wayne Phillips  2014/10/21】
access下如何恢复已经删除的记录;如何恢复已经删除的表、窗体等...  【宏鹏(转载)  2015/2/4】
转载SQLServer恢复表级数据   【金宇  2015/8/29】
常见问答
技术分类
相关资源
文章搜索
关于作者

崔宇

文章分类

文章存档

友情链接