Solved

VBA code to Compact and Repair Database

Posted on 2003-12-04
7
1,171 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 49

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now