Microsoft KB Archive/815280

= ACC2000: How to Recover Data from a Corrupted Table by Using the DAO Method =

Article ID: 815280

Article Last Modified on 10/14/2003

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article applies only to a Microsoft Access database (.mdb).

Moderate: Requires basic macro, coding, and interoperability skills.



SUMMARY
This article describes how to recover data from a corrupted table in an Access database. You can do this by using the Microsoft Data Access Objects (DAO) db.Execute method. You can use the db.Execute method when you cannot recover your data by using either MS Query or the Compact and Repair Database utility in Access.



MORE INFORMATION
Note The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected.

To recover the data from the corrupted table in Access, follow these steps:  Make a copy of the corrupted database. Exclude the corrupted tables. Name the database Recovered_Database . Open the Access database that contains the corrupted tables. Click Modules and then click New.  Put the following code in the new module:

Note The following code creates a table in Recovered_Database with the same name as the corrupted table (). Sub Recovery

Dim db As Database Dim sql As String

' Set the database to current database. Set db = CurrentDb

' Set sql to a string that represents the query to recover data from ' the corrupted table.  is the name of corrupted table. sql = &quot;SELECT .* INTO  in &quot; & _ &quot;'\Recovered_Database.mdb'&quot; & _ &quot; FROM <Corrupted_Table>&quot;

db.Execute sql

End Sub </li> On the File menu, click Save. Save the module as Module1 .</li> On the Run menu, click Run Sub/UserForm.</li> Repeat step 3 to step 6 for each corrupted table.</li></ol>

After you complete these steps:
 * Test the recovered database before you return the database to the production environment.
 * Do not delete the damaged database until you confirm the recovery.

<div class="references_section">