Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBA code to Compact and Repair Database

Posted on 2003-12-04
7
Medium Priority
?
1,213 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 53

Accepted Solution

by:
Ryan Chong earned 1000 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
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 
LVL 58
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

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

670 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