Compacting linked database

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I am using a datebase that is linked to a database
containing the data tables. I have set the main database
to compact on close, but I would like to be able to
compact the linked database automatically when I close
the main database.

Can this be done, and if so, how?
 
Mike,

Here's an example of the code I use for this...

Dim strDBPath As String
Dim strDBFile As String
Dim CurrentDBDir As String
strDBPath = CurrentDb.Name
strDBFile = Dir(strDBPath)
CurrentDBDir = Left(strDBPath, Len(strDBPath) - Len(strDBFile))
If Len(Dir(CurrentDBDir & "\MyDB_bu.mdb")) Then
Kill CurrentDBDir & "\MyDB_bu.mdb"
End If
If Len(Dir(CurrentDBDir & "\MyDB_be.ldb")) Then
'do nothing
ElseIf Len(Dir(CurrentDBDir & "\MyDB_be.mdb")) Then
DBEngine.CompactDatabase CurrentDBDir & "\MyDB_be.mdb", _
CurrentDBDir & "\MyDB_bu.mdb"
Kill CurrentDBDir & "\MyDB_be.mdb"
Name CurrentDBDir & "\MyDB_bu.mdb" As CurrentDBDir & "\MyDB_be.mdb"
End If

This assumes the backend is in the same directory as the frontend. If
this is not the case, you will need to modify the code to detect the
location of the backend database.
 
Back
Top