Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Compacting an MS Access database from Delphi...

Posted on 2003-03-24
1
Medium Priority
?
298 Views
Last Modified: 2010-04-04
Hi!
I need to be able to compact an MS Access database from delphi.
Is there anybody out there who knows how i can do so??? If it is possible, I would like to be able to do this without having MS Access installed on the computer I am running the application.

Thanx!

micfro
0
Comment
Question by:micfro
1 Comment
 
LVL 3

Accepted Solution

by:
marcoszorrilla earned 150 total points
ID: 8195287
Try with this function  using the ADO technology

Function CompactAndRepair(sOldMDB : String; sNewMDB : String) : Boolean;
const
       sProvider = 'Provider=Microsoft.Jet.OLEDB.4.0;';
var
       oJetEng   : JetEngine;
begin
       sOldMDB := sProvider + 'Data Source=' + sOldMDB;
       sNewMDB := sProvider + 'Data Source=' + sNewMDB;

       try
          oJetEng := CoJetEngine.Create;
          oJetEng.CompactDatabase(sOldMDB, sNewMDB);
          oJetEng := Nil;
          Result  := True;
       except
          oJetEng := Nil;
          Result  := False;
       end;
end;


Example :

if CompactAndRepair('e:\Old.mdb', 'e:\New.mdb') then
 ShowMessage('Successfully')
else
 ShowMessage('Error?');

if you would like to use DAO for old database like Access
97

uses ComObj;
procedure TForm1.Button1Click(Sender: TObject);
var
dao: OLEVariant;
begin
dao := CreateOleObject('DAO.DBEngine.35');
dao.CompactDatabase('C:\My Documents\DB1.mdb',
'C:\My Documents\CompactedDB1.mdb');
end;


Best Regards.
Marcos.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question