access2000或者2003压缩修复异常解决方式

如果你压缩修复数据库时遇到奔溃并且报这样错误的时候可以试试这样去恢复


错误;

"The database is in an unexpected state. Microsoft Access can't open it.
This database has been converted from a prior version of MS Access by using
the DAO compact database method instead of the convert database command on
the tools menu (database utilities sub menu). This has left the database in
a partially converted state. If you have a copy of the database in its
original format, use the convert database command on the tools menu
(database utilities submenu) to convert it."


解决方式:


1. Make a backup copy of the original database.

2. Start Microsoft Access.

3. Create a new, blank database.

4. Press ALT+F11 or on the Insert menu, click Module to launch the Visual
Basic Editor in a separate window, and will create a new module for you.

5. On the Tools menu, click References. This will display a References
dialog box.

6. Scroll down through the list, and check the box next to "Microsoft DAO
3.6 Object Library".

7. Click OK to close the References dialog box.

8. Copy and paste the following code into the new module that is open on
the screen:

Sub RecoverCorruptDB()
        Dim dbCorrupt As DAO.Database
        Dim dbCurrent As DAO.Database
        Dim td As DAO.TableDef
        Dim tdNew As DAO.TableDef
        Dim fld As DAO.Field
        Dim fldNew As DAO.Field
        Dim ind As DAO.Index
        Dim indNew As DAO.Index
        Dim qd As DAO.QueryDef
        Dim qdNew As DAO.QueryDef
        Dim strDBPath As String
        Dim strQry As String

'Replace the path below to the path of the corrupted database

        strDBPath = "C:\My Documents\Appraisals.mdb"
        On Error Resume Next
        Set dbCurrent = CurrentDb
        Set dbCorrupt = OpenDatabase(strDBPath)
        For Each td In dbCorrupt.TableDefs
                If Left(td.Name, 4) <> "MSys" Then
                    

strQry = "SELECT * INTO [" & td.Name & "] FROM [" & td.Name & "] IN '" & dbCorrupt.Name & "'"

                    dbCurrent.Execute strQry, dbFailOnError
                    dbCurrent.TableDefs.Refresh
                    Set tdNew = dbCurrent.TableDefs(td.Name)

'Recreate the indexes on the table

                    For Each ind In td.Indexes
                        Set indNew = tdNew.CreateIndex(ind.Name)
                        For Each fld In ind.Fields
                            Set fldNew = indNew.CreateField(fld.Name)
                            indNew.Fields.Append fldNew
                        Next
                        indNew.Primary = ind.Primary
                        indNew.Unique = ind.Unique
                        indNew.IgnoreNulls = ind.IgnoreNulls
                        tdNew.Indexes.Append indNew
                        tdNew.Indexes.Refresh
                    Next
                End If
        Next

'Recreate the queries

        For Each qd In dbCorrupt.QueryDefs
                If Left(qd.Name, 4) <> "~sq_" Then
                    Set qdNew = dbCurrent.CreateQueryDef(qd.Name, qd.SQL)
                End If
        Next
        dbCorrupt.Close
        Application.RefreshDatabaseWindow

        MsgBox "Procedure Complete."
End Sub


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值