Compacting and Repairing Code

  • Thread starter Thread starter Andro Dgebuadze
  • Start date Start date
A

Andro Dgebuadze

Hi there

I have 2 mdb files in 1 directory A.mdb and B.mdb
In A.mdb I want to write a code which will compact and repair B.mdb
Please Help...


Andro
 
Andro,

Here's some sample code that compacts all databases in one directory into
another... more that you're asking for, but will give you the idea:

Sub compact_all_databases()
Dim fs, f, f1
src = "C:\Documents\Access\" 'source folder
tgt = "C:\Documents\Temp\" 'target folder
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(src)
Set f1 = f.Files
For Each f2 In f1
If Right(f2.Name, 4) = ".mdb" Then
oldnam = src & f2.Name
newnam = tgt & f2.Name
On Error GoTo next_db
DBEngine.CompactDatabase oldnam, newnam
On Error GoTo 0
Debug.Print f2.Name
End If
next_db:
Next

End Sub

HTH,
Nikos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top