VBA; Access: compact and repair split db

Posted on 2007-07-31
Medium Priority
Last Modified: 2012-05-05
I have a split db in Access (application mdb front and data in a separate mdb file).  When user exits the application, I want to "compact and repair" the mdb file housing the data tables.  How can I do that?
Question by:Shelnutt
LVL 75
ID: 19603721
LVL 75
ID: 19603726
LVL 44

Expert Comment

ID: 19603805
mx:  When you are 'linked' to tables in a backend mdb, you do not actually have the mdb 'opened' do you?   Are you saying that utility will compact and repair under that condition?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 38

Expert Comment

ID: 19603836
With a reference to DAO, you can use:

DBEngine.CompactDatabase strExistingFilename, strNewFilename

Otherwise, you can add a reference to Jet Replication Objects and use:
How To Compact Microsoft Access Database Through ADO
LVL 75
ID: 19603866
gRay ... I didn't say anything ... but I suggest everyone read the info on Michael's site ... regarding the subject ... and the various pros and cons of the methods.


Author Comment

ID: 19612875
After reading several posts, I was able to figure out how to solve my problem.  Here is the code I used:
Dim fs As FileSystemObject
Set fs = CreateObject("Scripting.FileSystemObject")
Dim SourceFile As String
Dim DestinationFile As String
Dim NewFile As String
Hourglass True
SourceFile = "c:\program files\superaudits\superaudits_bes.mdb"
DestinationFile = "c:\superaudits_bes_mdb"
NewFile = "c:\superaudits_besnew.mdb"
fs.CopyFile SourceFile, DestinationFile, True
DBEngine.CompactDatabase DestinationFile, NewFile
fs.CopyFile NewFile, SourceFile, True
fs.DeleteFile DestinationFile
fs.DeleteFile NewFile

None of the posts really resolved the issue.  The closest answer to what I needed was from PaulHews.
Thank you all very much for your time!
LVL 75
ID: 19612909
Thank you for posting your solution ... we appreciate that.


Accepted Solution

Computer101 earned 0 total points
ID: 21133206
PAQed with points refunded (125)

EE Admin

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…
Suggested Courses

809 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