DAO CompactDatabase Error/Corruption (1 Viewer)

jgreen

New member
Local time
Today, 05:02
Joined
Dec 30, 2004
Messages
3
Hello,

I have read previous threads discussing the same issue, but I cannot get the solutions to work. :eek: Please help!!



This is the error message I receive when trying to open the db:
"This database is in an unexpected stat;Microsoft Access can't open it.

This database has been converted froma prior version of Microsoft Access by using the DAO CompactDatabase method instead of the Convert Database command on the Tools menu (Database Utilities submenu). 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 to convert it. IF the original database is no longer available, create a new database and import your tables and queries to preserve your data. Your other database objects can't be recovered
."



When I try to import from the corrupted version into the back up version we have, I get the exact same error message - that it cannot be opened.



I kept reading threads and came across some code to paste into a new Module screen, but it doesn't work for me either (Changed strDBpath to our db's path as instructed):
"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"



Is there anything else that I can possibly try? Or am I doing something wrong? Please speak to me as if I were as dumb as a box of rocks. I have had classes for Access Begin/Intermed/Adv., but am not at all adept at the coding, VBA, modules, macros, etc...

Thank you for any info you may have!!!
 

Users who are viewing this thread

Top Bottom