PC Review


Reply
Thread Tools Rate Thread

Decompile, Compact & Repair from VBA code.

 
 
Jeremy Gollehon
Guest
Posts: n/a
 
      28th Apr 2006
I wanted to Decompile, Compact & Repair from VBA code but couldn't find a
complete solution online. Here's one for you to use and for me to find with
Google Groups search in the future. :-)

I've found that to truely compact an access mdb to it's optimal size the
following process is required. (Access 2003)

1) Compact & Repair
2) Close the file.
3) Open with a shortcut using the /Decompile switch.
4) Compact & Repair.
5) Close the file.

---------------------------------------------------------------------------
Sub TruelyCompactAndRepair()
Dim sFileName As String
Dim appAccess As New Access.Application

sFileName = "D:\Test.mdb"

'Open.
appAccess.OpenCurrentDatabase sFileName
'Compact & Repair.
appAccess.CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Database utilities"). _
Controls("Compact and repair database...").accDoDefaultAction

'Close.
appAccess.CloseCurrentDatabase
appAccess.Quit

'Opens & Decompiles.
Shell "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE /Decompile
""" & sFileName & """"

'Close
Set appAccess = GetObject(sFileName)
appAccess.CloseCurrentDatabase
appAccess.Quit

'Opens, Compacts & Repairs, then Closes.
Shell "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE /Repair """
& sFileName & """"

End Sub
---------------------------------------------------------------------------

If you're looking at the code and wondering why it doesn't use the shell
command for the first Compact & Repair, it's because VBA doesn't wait for
the Shell command to finish when using the /Repair switch. Luckily it does
when using the /Decompile switch which allows for the use of GetObject to
close the mdb. Then a simple /Repair does steps 4 and 5 all with one simple
line of code.

Please note this code must be run from another instance of Access, or any
other VBA programming environment except the one specified in sFileName.

Hopefully someone get's some use out of this. I use it in conjuction with:
http://snipurl.com/DisallowDesignChange posted by Wayne Morgan. When
preparing to deploy a new mdb I run TruelyCompactAndRepair calling his
procedure before the first Compact & Repair.

-Jeremy


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compact and repair through a VB code Pietro Microsoft Access 2 14th Feb 2008 02:22 PM
Code to compact and repair =?Utf-8?B?dHJveQ==?= Microsoft Access Form Coding 1 10th May 2006 07:06 AM
Decompile, Compact & Repair from VBA code. Jeremy Gollehon Microsoft Access 0 28th Apr 2006 06:57 PM
Decompile, Compact & Repair from VBA code. Jeremy Gollehon Microsoft Access Form Coding 0 28th Apr 2006 06:57 PM
Compact Repair code? =?Utf-8?B?TWFCZWxs?= Microsoft Access VBA Modules 4 2nd Aug 2005 10:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:38 PM.