Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 28,221 times

Related Categories

Compact and repair Jet databases with DAO

If you're like most developers, you've run into problems with Microsoft
Access databases. Access' databases are typically reliable, but
occasionally they can get damaged. There are numerous reasons why, such
as powering down the computer without first closing the database file or
the system simply crashing. Another source of problems for databases is
excessive fragmentation-when records are deleted from a database file, the
file becomes fragmented. Whatever the reason, once the database is damaged,
end-users are often left stranded until technical support finds the time to
help them. Fortunately, you can take measures to help users quickly recover
from such problems, by providing built-in utilities that perform routine
database maintenance.

The DAO library provides two methods to perform the necessary maintenance
that keeps Access databases running smoothly--RepairDatabase and
CompactDatabase. The RepairDatabase method uses the syntax

RepairDatabase dbname

where dbname is a string representing the full pathname of the Access
database (.MDB) that you need to repair. This CompactDatabase method uses
the following syntax:

CompactDatabase olddb, newdb, _
locale, options, password


You specify the full path and filename of your source database as a string
in the method's olddb property. Likewise, you specify the destination of
the compacted database with the newdb property.

So, to use these statements, you could add code similar to:

RepairDatabase "C:\myData1.mdb"
CompactDatabase "C:\myData1.mdb", App.Path & "myDataNewName.mdb"


If you use DA0 3.6, then you can remove the RepairDatabase statement.
DAO 3.0 incorporates this functionality into the CompactDatabase method-you
can no longer compact and repair databases as separate actions.

© 2001 Element K Journals, a division of Element K Press LLC ("Element K"). Element K and the Element K logo are trademarks of Element K LLC

Comments

  • Close but...

    Posted by yourfriendmike on 03 Mar 2005


    I was wanting to put a compact button on a form to have the user quickly and consistently keep compressing the current DB they were in. This is because the users in the DB are constantly deleting, ...