Solved

VBA code to Compact and Repair Database

Posted on 2003-12-04
7
1,183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 52

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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

734 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