Code for compacting a database

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

On this page I found code for compacting the database.

http://www.mvps.org/access/general/gen0041.htm

Im not too sure whether it is code for VBA or a module. Can someone clarify?

Cheers

As a PS, I found the database can't be compacted as part of a macro, yet
under "RunCommand" there is an option for "compactdatabase" !! Wierd.
 
scubadiver ha scritto:
On this page I found code for compacting the database.

http://www.mvps.org/access/general/gen0041.htm

Im not too sure whether it is code for VBA or a module. Can someone clarify?

Cheers

As a PS, I found the database can't be compacted as part of a macro, yet
under "RunCommand" there is an option for "compactdatabase" !! Wierd.

You don't tell us your Access Version....!
From A2000 you can use:

CommandBars("Menu Bar"). _
Controls("Strumenti"). _
Controls("Utilità database"). _
Controls("Compatta e ripristina database..."). _
accDoDefaultAction

With A97 you need to delegate to an external application, you can use
thid DEMO:

http://www.alessandrobaraldi.it/DettaglioFaq.asp?IdFAQ=151

@Alex
 
scubadiver ha scritto:
I am using version 2000


So you can point directly to Access Menù Controls item.
In my suggestion i make a mistake ... i give you the Italian
reference..., i have not English version, so you can run trought the
menù to have the right EN reference...!

May be like this, but if anyone can translate on EN version will be
appreciated...:

CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Utilitity database"). _
Controls("Compact and restore..."). _
accDoDefaultAction

@Alex
 
scubadiver ha scritto:
My question still hasn't been answered !

How do I insert the code?


You need learn the code base first....!
This code below is executable on Event.....
Wich event...?
You need to Know how and where, i think may be usefull to execute on
Function_Key
or a MenùButton or a commandButton Click Event...!

In the first case you need to use AutoKeys macro within {F10} as name,
and in execution code you need to call a function =Compact()

Public Function Compact()
CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Utilitity database"). _
Controls("Compact and restore..."). _
accDoDefaultAction
End Function

In the 2° one you need always to use this function but the call run by
the menu action.

At last on Click event

Private Sub cmdButtonname_Click()
CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Utilitity database"). _
Controls("Compact and restore..."). _
accDoDefaultAction
End Sub

@Alex
 
scubadiver: One choice is to put the code behind a button on your main menu
form. Here's an exemple:

Private Sub Command13_Click()
CommandBars("Menu Bar").Controls("Tools").Controls("Database
Utilities").Controls("Compact and repair database...").accDoDefaultAction
End Sub

Of course, your sub name will be different, depending on your control name.

Or you can insert the code into another sub or function in a module...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top