compacting in code

  • Thread starter Thread starter Trish
  • Start date Start date
T

Trish

I would like my database to automatically compact itself
everytime the user closes a particular form. Is there
some way to do this in code in the Form_OnClose routine??
I found a method called DBEngine.CompactDatabase but it
seems as though I can only do that on a database that is
already closed. Is there something similar to this that I
can do (much like going directly to the compact option in
the Tools menu)??

Thanks!
 
I would like my database to automatically compact itself
everytime the user closes a particular form. Is there
some way to do this in code in the Form_OnClose routine??
I found a method called DBEngine.CompactDatabase but it
seems as though I can only do that on a database that is
already closed. Is there something similar to this that I
can do (much like going directly to the compact option in
the Tools menu)??

You can't close the currently open database in code. You might look into Michael
Kaplan's free TSI SOON database add-in as a solution:

http://www.trigeminal.com/lang/1033/utility.asp?ItemID=8#8
 
I might also mention that this desired "benefit" may be
dangerous ... especially in the hands of a general user
who doesn't know it plans on doing this upon exit.

First: on occassion the compact process itself,
particuarly in Access97, itself tended to corrupt
databases.

Second: if the compact takes any longer than 0.001 seconds
don't count on your user waiting around before turning off
their computer, or even going to the task manager and
terminating the process in a huff of "why isn't this
stupid thing going away" ...
 
I might also mention that this desired "benefit" may be
dangerous ... especially in the hands of a general user
who doesn't know it plans on doing this upon exit.

So, warn the user that it is going to happen.
First: on occassion the compact process itself,
particuarly in Access97, itself tended to corrupt
databases.

I've never personally experienced corruption caused by compacting a database
file in Access 97, nor in any other version of Access since 2.0. I *have*
experienced it when modifying objects and code, however, in every version since
97.
Second: if the compact takes any longer than 0.001 seconds
don't count on your user waiting around before turning off
their computer, or even going to the task manager and
terminating the process in a huff of "why isn't this
stupid thing going away" ...

Those users are likely the ones who use the power switch anyway.
 
If you application is split into a front-end/back-end structure, you can
compact the back-end database, from code within the front-end database, as
long as no front-end forms or reports have back-end tables open at that
time.

The ability to do this is one of the advantages of using the
front-end/back-end approach.

HTH,
TC
 
Back
Top