Para compactar una Base de Datos en Access:
Código Delphi
[-]
var Dir: string;
function GetEngine(var DbEngine: Variant): Boolean;
begin
Result := False;
try
DbEngine := CreateOleObject('Dao.DbEngine.35'); except
try
DbEngine := CreateOleObject('Dao.DbEngine.36'); except
ShowMessage('No es posible inicializar el DAO.'#13 +
'Microsoft DAO debe de estar instalado en este equipo.'#13 +
'Para instalarlo, debes saber que forma parte de '+
'MS Access, Visual Basic, MS Office, etc.');
Exit;
end;
end;
Result := VarType(DbEngine) = VarDispatch;
end;
function CompactDataBaseDao(DbAccessName: String): Boolean;
var
DbEngine: Variant;
TmpFile: String;
begin
Result := False;
if Dir = '' then Exit;
TmpFile := Dir + 'TmpAccess.Mdb';
if Pos( '.MDB', UpperCase(DbAccessName)) = 0 then
DbAccessName := DbAccessName + '.MDB';
if not FileExists(DbAccessName) then Exit;
try
if not GetEngine(DbEngine) then Exit;
if FileExists(TmpFile) then
DeleteFile(TmpFile);
DbEngine.CompactDataBase(DbAccessName, TmpFile);
DeleteFile(DbAccessName);
RenameFile(TmpFile, DbAccessName);
Result := True;
except
Exit;
end;
end;