Board index » delphi » Compacting ACCESS from within a DELPHI apps

Compacting ACCESS from within a DELPHI apps

I want to provide a menu option for the user to compact the ACCESS
database.  I figured out I need to use the VB
'DBEngine.CompactDatabase' command.

How can I invoke this from within my DELPHI apps?

Thanks, regards

Chris

 

Re:Compacting ACCESS from within a DELPHI apps


Here's a routine that will do the trick.  It get's all the information
it needs about the Access database and path from the BDE alias.

Ray

function TMainForm.PackAccessDB(): boolean;
var varDBEngine: variant;
    slDBParams: TStringList;
    strDBPathName,
    strTempPathName: string;
begin
  result := true;
  slDBParams := TStringList.Create;
  try
    dbModule.Payroll.Session.GetAliasParams('Payroll', slDBParams);
    strDBPathName := slDBParams.Values['DATABASE NAME'];
    strTempPathName := ExtractFilePath(strDBPathName);
    strTempPathName := strTempPathName + 'temp.mdb';
    varDBEngine := CreateOleObject('DAO.DBEngine.35');
    try
      dbModule.Payroll.Connected := false;
      varDBEngine.CompactDatabase(strDBPathName, strTempPathName);
      DeleteFile(strDBPathName);
      RenameFile(strTempPathName, strDBPathName);
    except
      result := false;
    end;
  finally
    slDBParams.Free;
    varDBEngine := Unassigned;
    dbModule.Payroll.Connected := true;
  end;
end;

On Mon, 26 Oct 1998 22:45:08 +1100, "Chris Birmele" <birm...@ibm.net>
wrote:

Quote
>I want to provide a menu option for the user to compact the ACCESS
>database.  I figured out I need to use the VB
>'DBEngine.CompactDatabase' command.

>How can I invoke this from within my DELPHI apps?

>Thanks, regards

>Chris

==================================
Ray Porter
Applications Analyst Programmer
Administrative Information Services
The University of North Carolina at Chapel Hill
Phone: 919-966-5878
Home Page: http://www.unc.edu/~dragon/

"Meddle not in the affairs of dragons,
for you are crunchy and taste good with ketchup."

Other Threads