Solved

VBA code to Compact and Repair Database

Posted on 2003-12-04
7
1,174 Views
Last Modified: 2010-05-18
I have a database (ike_gr.mdb – at the final it will be ike_gr.mde) and I want to use some VBA code which will run automatically every two-three weeks and do the same as the Compact and Repair Database menu does (I don’t want to use the menu).
Please give me a code for this.
I use Access 2002.
0
Comment
Question by:gavrinas
7 Comments
 
LVL 50

Accepted Solution

by:
Ryan Chong earned 250 total points
ID: 9873352
See this recent PAQ question:
http://www.experts-exchange.com/Databases/MS_Access/Q_20813409.html

Hope this helps
0
 
LVL 1

Expert Comment

by:ExpertAudit
ID: 9873381
Dear gavrinas,

Here you can find a good explanation to your problem and  you can find a free com component to help you achieve what you want...

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

The Access Web is one of the best places around for Access related material.


0
 
LVL 32

Expert Comment

by:jadedata
ID: 9874361
Hey gavrinas!

This is the basics of some code I use in my switchboard to compact the front end file on user demand
It is located in the HandleButtonClick sub of the switchboard

  DoCmd.SelectObject acTable, , True
  DoCmd.Maximize
  SendKeys "%TDC"

once it runs, the front end "recycles" back up to the switchboard..

regards
Jack
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 57
ID: 9874404
Here's a simpler version of calling the command bar that was posted earlier (part B of the PAQ posted by ryancys).  Note that part "A" for compacting a remote database is not the same as compacting a MDB from the menu bar.  When you do a JET engine compact, your not fully compacting the database (The JET engine does not understand Access objects and therefore cannot compact them).

Note however that in *all* cases (part B, and solution by ExpertAudit, and my code), you cannot compact a currently open MDB, so all these methods will close, compact, and then re-open the MDB.  If you can live with that, great.  If not, I can suggest other approaches.

Jim.


Public Sub SelfCompact()
   With CommandBars.Add(, 1, , True)
       .Controls.Add 1, 2071, , , True
       .Visible = True
       .Controls(1).SetFocus
       DoEvents
       SendKeys "~"
   End With
End Sub


0
 
LVL 9

Expert Comment

by:ornicar
ID: 10075790
----------------------------------------------------------------------------------------
This question has been abandoned and needs to be finalized.
 You can accept an answer, split the points, or get a refund (information at http:/help.jsp#hs5)
  If you need a moderator to help you, post a question at Community Support (http:/Community_Support/)

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

ornicar
Cleanup Volunteer

---------------------------------------------------------------------------------------------
0
 
LVL 32

Expert Comment

by:jadedata
ID: 10262676
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: ryancys {http:#9873352}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jadedata
EE Cleanup Volunteer
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question