删除ACCESS数据库中表的方法 |
|
www.nanhushi.com 佚名 不详 |
示例代码使用 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
|
|
|
文章录入:杜斌 责任编辑:杜斌 |
|
上一篇文章: Access表结构修改方法 下一篇文章: Access报表中每隔行显示横线 |
【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |
|
|