How? I can't remember, as I haven't done any coding like that with
VB/Access since early 1996.
Brad
--
Brad Clarke
http://www.monisys.ca/~bclarke
Member of DCG Ottawa
E.T. wrote:
>you should be able to do this via OLE automation
Brad Clarke wrote:
>How? I can't remember
The DBEngine object's CompactDatabase and RepairDatabase
methods are documented in ..\Microsoft Shared\DAO\DAO35.HLP.
The latest BDE Access driver may have dbi functions which call the
DAO methods, but I doubt it somehow. Automation is the way to do it.
I use Opus DirectAccess which makes it a cinch, but provided you have
an appropriate license (eg Access installed) you can create the engine
using ComObj helper CreateOleObject, then invoking the methods
off the resulting variant.
For advanced recovery see
ftp.microsoft.com/Softlib/MSLFILES/JET35UPD.EXE
ftp.microsoft.com/Softlib/MSLFILES/JETERR35.EXE
"Jetcomp.exe, which is included with Jet35upd.exe, is a standalone
utility that allows you to compact databases created with Microsoft Jet
database engine 3.x. This utility may be used in conjunction with
Microsoft Jet database engine 3.51 for recovering corrupted databases.
Although it is possible to use the Microsoft Access Compact utility or the
CompactDatabase method with Microsoft Jet database engine 3.51,
Jetcomp.exe may be able to recover some databases that these utilities
could not. This is because the Microsoft Access Compact utility and the
CompactDatabase method attempt to open and close a database before
attempting to compact it. In certain cases where these utilities may not
be able to reopen the database, Compact will be unable to proceed,
preventing recovery of the database. Jetcomp.exe does not attempt to
open and close the database before compacting, and may be able to
recover some databases that the Microsoft Access compact utility and
the CompactDatabase method could not. Jetcomp.exe is a freely
distributable utility, but requires that you have one of the following
products installed:
- Microsoft Office 97
- Microsoft Access 97
- Microsoft Visual Basic 5.0
- A Microsoft Office Developer Edition 97 run-time application that
includes the run-time version of Microsoft Access 97
- A Microsoft Visual Basic 5.0 run-time application that includes
Microsoft Jet database engine 3.5"
procedure CompactDatabases;
var
dbEngine: Variant;
begin
if MessageDlg('Compacting the database requires ALL users
to'+chr(10)+
'be logged out of the program. Continue?',
mtConfirmation,[mbYes,mbNo],0) <> mrYes then
exit;
try
dbEngine := CreateOLEObject('DAO.DBEngine');
dbEngine.RepairDatabase(MyAccessDBName);
dbEngine.CompactDatabase(OldAccessName,NewAccessName,'',0,'');
except
on E: EOLEError do
ShowMessage(E.Message);
end;
end;
ShowMessage('Repair/Compact completed successfully.');
end;
One thing to keep in mind is that the CompactDatabase method requires
a different name than the one being compacted so you will have to make
sure that you copy or rename the new file back to the original name to
access it in your program.
Woody
E.T. wrote in message <36125d6c...@forums.inprise.com>...
const // DAO MSAccess Jet Engine constants
DAOMSJet = 'DAO.DBEngine.35'; // or may be 'DAO.DBEngine'
var
DBEngine: variant;
begin
try
DBEngine := CreateOleObject('DAO.DBEngine.35');
DBEngine.RepairDatabase ('d:\data\db1.mdb');
finally
dbengine := unassigned;
end;
end;