Link to home
Start Free TrialLog in
Avatar of Shelnutt
Shelnutt

asked on

VBA; Access: compact and repair split db

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?
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

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?
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
http://support.microsoft.com/kb/230501
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.

mx
Avatar of Shelnutt
Shelnutt

ASKER

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!
Thank you for posting your solution ... we appreciate that.

mx
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial