设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

12
返回列表 发新帖
楼主: 一日千里
打印 上一主题 下一主题

[其它] 请教 表 删除后去哪了?能恢复吗??谢谢!!![color=#DC143C]加急!!!![/co

[复制链接]
11#
发表于 2006-3-4 16:38:00 | 只看该作者
恢復刪除的工作表(未被壓縮)<RE><FONT size=3>ublic Function FnUndeleteObjects() As Boolean

  On Error GoTo ErrorHandler:

  Dim strObjectName As String

  Dim rsTables As DAO.Recordset

  Dim dbsDatabase As DAO.Database

  Dim tDef As DAO.TableDef

  Dim qDef As DAO.QueryDef

  Dim intNumDeletedItemsFound As Integer

  Set dbsDatabase = CurrentDb

  For Each tDef In dbsDatabase.TableDefs

      'This is actually used as a 'Deleted Flag'

      If tDef.Attributes And dbHiddenObject Then

         strObjectName = FnGetDeletedTableNameByProp(tDef.Name)

         strObjectName = InputBox("A deleted TABLE has been found." & _

                         vbCrLf & vbCrLf & _

                         "To undelete this object, enter a new name:", _

                         "Access Undelete Table", strObjectName)



         If Len(strObjectName) > 0 Then

            FnUndeleteTable CurrentDb, tDef.Name, strObjectName

         End If

         intNumDeletedItemsFound = intNumDeletedItemsFound + 1

      End If

  Next tDef



  For Each qDef In dbsDatabase.QueryDefs

      'Note 'Attributes' flag is not exposed for QueryDef objects,

      'We could look up the flag by using MSysObjects but

      'new queries don't get written to MSysObjects until

      'Access is closed. Therefore we'll just check the

      'start of the name is '~TMPCLP' ...

      If InStr(1, qDef.Name, "~TMPCLP") = 1 Then

         strObjectName = ""

         strObjectName = InputBox("A deleted QUERY has been found." & _

                         vbCrLf & vbCrLf & _

                         "To undelete this object, enter a new name:", _

                         "Access Undelete Query", strObjectName)



         If Len(strObjectName) > 0 Then

            If FnUndeleteQuery(CurrentDb, qDef.Name, strObjectName) Then

               'We'll rename the deleted object since we've made a

               'copy and won't be needing to re-undelete it.

               '(To break the condition "~TMPCLP" in future...)

                qDef.Name = "~TMPCLQ" & Right$(qDef.Name, Len(qDef.Name) - 7)

             End If

         End If

         intNumDeletedItemsFound = intNumDeletedItemsFound + 1

      End If

  Next qDef

  If intNumDeletedItemsFound = 0 Then

     MsgBox "Unable to find any deleted tables/queries to undelete!"

  End If



  Set dbsDatabase = Nothing

  FnUndeleteObjects = True

ExitFunction:

  Exit Function

ErrorHandler:

  MsgBox "Error occured in FnUndeleteObjects() - " & _

         Err.Description & " (" & CStr(Err.Number) & ")"

  GoTo ExitFunction

End Function





Private Function FnUndeleteTable(dbDatabase As DAO.Database, _

                 strDeletedTableName As String, _

                 strNewTableName As String)



  Dim tDef As DAO.TableDef

  Set tDef = dbDatabase.TableDefs(strDeletedTableName)

  'Remove the Deleted Flag...

  tDef.Attributes = tDef.Attributes And Not dbHiddenObject

  'Rename the deleted object to the original or new name...

  tDef.Name = strNewTableName

  dbDatabase.TableDefs.Refresh

  Application.RefreshDatabaseWindow

  Set tDef = Nothing

End Function



Private Function FnUndeleteQuery(dbDatabase As DAO.Database, _

                 strDeletedQueryName As String, _

                 strNewQueryName As String)



  'We can't just remove the Deleted flag on queries

  '('Attributes' is not an exposed property)

  'So instead we create a new query with the SQL...



  'Note: Can't use DoCmd.CopyObject as it copies the dbHiddenObject attribute!



  If FnCopyQuery(dbDatabase, strDeletedQueryName, strNewQueryName) Then

     FnUndeleteQuery = True

     Application.RefreshDatabaseWindow

  End If

End Function





Private Function FnCopyQuery(dbDatabase As DAO.Database, _

                 strSourceName As String, _

                 strDestinationName As String)



  On Error GoTo ErrorHandler:



  Dim qDefOld As DAO.QueryDef

  Dim qDefNew As DAO.QueryDef

  Dim Field As DAO.Field



  Set qDefOld = dbDat
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2025-1-10 16:15 , Processed in 0.318622 second(s), 22 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表