Hi

Anyone know how to correct a currupted database using vb code? Please help me out to solve........

Dani AI

Generated

The replies from , and correctly point at Access’s built‑in compact/repair and at programmatic options; is also right that the built‑in wizard often only saves tables while forms/reports or VBA can be lost. Below is a compact, practical recovery workflow (least invasive first), plus a few advanced tips missing from earlier replies.

  1. Immediate safety steps
  • Make a binary copy of the MDB/ACCDB before any repair attempt.
  • If multiple users, ensure the file is closed everywhere and remove any lock file (.ldb/.laccdb) only after confirming no active sessions.
  • Try the Access GUI Compact & Repair and open the file while holding SHIFT to bypass startup code.
  1. If Compact & Repair fails
  • Open Access exclusively (Open > Open Exclusive) and attempt to import objects into a brand‑new blank database: import tables first, then queries, then forms/reports. Importing into a new file often bypasses corruption in the container.
  • If table data is critical, link the broken file from a new Access file or ODBC client and export table data to CSV/Excel to preserve raw rows before further work. This preserves data even when design objects are damaged.
  1. Advanced steps and environment notes
  • For corrupted VBA projects, run Access with the decompile switch, then compact/repair and recompile (example: msaccess.exe /decompile "C:\path\file.mdb").
  • For older Jet MDBs that Access cannot fix, Microsoft's Jet Compact Utility (JetComp) has historically recovered files that the normal wizard cannot. Try running recovery on a copy only.
  • Attempt recovery on a machine with the same Access/Jet/ACE version and bitness that originally created the file; version/bitness mismatches can prevent successful repair.
  1. Last resorts and prevention
  • Third‑party recovery tools (as others suggested) can be tried with demos that preview recoverable objects; use reputable vendors and verify results on copies. If recovery works, export and rebuild objects in a new database rather than trusting the repaired file long term.
  • After recovery, implement scheduled backups, periodic compacts, and source control/export of form/report modules to reduce future risk.

Recommended Answers

All 7 Replies

Hi

Anyone know how to correct a currupted database using vb code? Please help me out to solve........

Have you tried doing this manually?

Hi,

Use This Code:
Repairs C:\DB1.mdb

Dim TempStr As String
Dim OrigStr As String
OrigStr = "C:\DB1.mdb"
TempStr ="C:\DBTemp.mdb"
'
On Error Resume Next
Kill TempStr
DBEngine.RepairDatabase OrigStr, TempStr
Kill OrigStr
FileCopy TempStr, OrigStr
Kill TempStr

Msgbox "Repaired Successfully"

Regards
Veena

Microsoft access 2003 has a wizard to repair databases built - in this only recovers tables though, forms and reports get lost

In most cases MS-Access inbuilt utilities recover these kind of corrupted databases, but its not guaranteed that it can your database too.

For this problem one software comes in my mind Stellar Phoenix Access Recovery it will help you to recover data which is not accessible due to corruption in Access databases, Tables, Queries, Forms, or Reports.

Just try free trial version <url snipped> it will scan your database and after that you will be able to see your recovered database.

If you are pleased with that buy full version of this software so that you can save your recovered database.

You can use following method and code to recover corrupted database.

1.DBEngine.CompactDatabase strInput strOutput

This compacts the database. strInput is the database file to be actioned on and strOutput is the resultant compacted database file name.

2. DBEngine.RepairDatabase strInput

This repairs a database. A trapable error 3049 can be checked for. This error indicates the database is possibly corrupt and therefore RepairDatabase method can be implemented.

To open a database exclusively:

Set db = dbEngine.Workspaces(0).OpenDatabase (strDBase,True)

If still errors comes, it means database is critically corrupt. You should have backup of this database file or use some good access repair software like Stellar Phoenix access recovery. This supports all version of microsoft access and in demo version you can check your repaired database.

Good Luck

Hi,

If the methods above still don't work, you may try a tool called Advanced Access Repair. This tool is rather useful in salvaging damaged Access MDB files.

You can use following method to recover corrupted database.

1. To compacts the database.
DBEngine.CompactDatabase strInput strOutput

strInput is the database file to be actioned on and strOutput is the resultant compacted database file name.

2. To repairs a database.
DBEngine.RepairDatabase strInput

3. To open a database exclusively:
Set db = dbEngine.Workspaces(0).OpenDatabase (strDBase,True)

If still you face the errors, it means database is critically corrupted. To repair your database you need the third party access database repair software.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.