Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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.

↑ Back to the top


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:
  1. Make a copy of the corrupted database. Exclude the corrupted tables. Name the database Recovered_Database.
  2. Open the Access database that contains the corrupted tables.
  3. Click Modules and then click New.
  4. 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 (<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.  <Corrupted_Table> is the name of corrupted table.
        sql = "SELECT <Corrupted_Table>.* INTO <Corrupted_Table> in " & _
          "'<Absolute_Path_of_Recovered_Database>\Recovered_Database.mdb'" & _
          " FROM <Corrupted_Table>"
    
        db.Execute sql
    
    End Sub
  5. On the File menu, click Save. Save the module as Module1.
  6. On the Run menu, click Run Sub/UserForm.
  7. Repeat step 3 to step 6 for each corrupted table.
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.

↑ Back to the top


References

For additional information about troubleshooting the corrupted database and how to recover data from a corrupted table, click the following article numbers to view the articles in the Microsoft Knowledge Base:
306204 ACC2000: How to Troubleshoot Corruption in a Microsoft Access Database
209137 ACC2000: How to Troubleshoot and Repair a Damaged Jet 4.0 Database
247771 ACC2000: How to Recover Data from a Damaged (Corrupted) Table
304561 ACC2000: How to Use MS Query to Recover Data from a Damaged Jet 4.0 Database

↑ Back to the top


Keywords: KB815280, kbhowto

↑ Back to the top

Article Info
Article ID : 815280
Revision : 2
Created on : 10/14/2003
Published on : 10/14/2003
Exists online : False
Views : 340