Compact and Repair question

  • Thread starter Thread starter Randal
  • Start date Start date
R

Randal

I am running macros in database #1 by calling them from database #2.
Database 1 is never opened. Is there a way to compact and repair database
#1 from database #2 without having to open #1 manually and use the "Database
Utilities" menu option?
 
There's a CompactDatabase method in DAO. Something like the following untest
air-code should work:

Dim strBackup As String
Dim strDatabase As String

strDatabase = "C:\Folder\DB1.mdb"

' Create the name of the backup database file
' This will be the file name with .bak, rather than .mdb

strBackup = "C:\Folder\DB1.bak"

' Delete the backup file if it already exists.

If Len(Dir(strBackup)) > 0 Then
Kill strBackup
End If

' Rename the existing database to the backup name

Name strDatabase As strBackup

' Compact the database

DBEngine.CompactDatabase strBackup, strDatabase



Alternatively, you can use JRO (see http://support.microsoft.com/?id=230501)
 
Back
Top