ADO Database Delphi

Title: To compact or repair MS Access database
Question: How to compact or repair the access database from within delphi
Answer:
If you works with MS Access database, I sure that time-to-time you needs to compact your database. Of course, very useful to run a some process within own application.
In the next code I demonstrates how you can do it:
var
dao: OLEVariant;
begin
dao := CreateOleObject('DAO.DBEngine.35');
dao.CompactDatabase('d:\yourDatabaseName.mdb',
'd:\yourNewCompactedDatabaseName.mdb');
end;
If you want to remove the old non-compacted database, you can simply to rename the new database file.
The MS Access is not very stable database and in network mode you can lose the data. In this case you can try to repair the database.
In the next code I demonstrates how you can do it:
var
dao: OLEVariant;
begin
dao := CreateOleObject('DAO.DBEngine.35');
dao.RepairDatabase('d:\yourDatabaseName.mdb');
end;
If you have the DAO 3.6, you must change the 'DAO.DBEngine.35' string to 'DAO.DBEngine.36'.