?
Solved

Compacting an MS Access database from Delphi...

Posted on 2003-03-24
1
Medium Priority
?
296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

764 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