Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compacting a database within a macro 1

Status
Not open for further replies.

balllian

MIS
Jan 26, 2005
150
GB
I have got a delete query set up within a macro and after running this delete i want to follow it up with running a compacting of the database.

how can i do this as there doesnt seem to the option to do this within a macro??

Any help with this would be greatly appreciated.

Thanks

 
Here is a function which you can paste into a module in your database. You can then run it from a command button, or a switchboard menu option:
Code:
Function CompactDatabase()

'----------------------------------------------------
'- Compact the database.  This only works if:       -
'- It is the only code in the function;             -
'- The function is called from the last line of     -
'- another VB procedure, or a Switchboard command   -
'----------------------------------------------------
   CommandBars("Menu Bar"). _
   Controls("Tools"). _
   Controls("Database utilities"). _
   Controls("Compact and repair database..."). _
   accDoDefaultAction

End Function
If you call this via a switchboard menu:

Text - Your choice, e.g. 'Compact The Database'
Command - Run Code
Function Name - CompactDatabase

I hope that this is useful.

Bob Stubbs
 
i have another couple of pieces of code within the database, will this cause this function not to work?

 
There is no problem with other code elsewhere ... it is just that this piece of code must not be followed by anything else. For example, if you tried to follow the existing code with:
Code:
Msgbox "Compact process finished", vbInformation
... then it would not work.

An easy way to experiment with this, is to create a test form in your database. Put one command button on the form, then call the CompactDatabase function from the button's On_click event.

Bob Stubbs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top