VBUser,
I have a lot of databases in a folder at work. I compact them weekly. Here is a function I wrote to compact all databases in a given folder
Public Function CompactDB(ByVal dirPath As String)
'Compacts all databases in given dir
Dim S As Variant
Dim je As New JRO.JetEngine
Dim fso As FileSystemObject
Dim fsoFolder As Folder
Dim fsoFile, tempFile As File
Dim tempName As String
'Make a new File System object.
Set fso = New FileSystemObject
' Get the FSO Folder (directory) object.
If Len(Dir(dirPath)) Then
Set fsoFolder = fso.GetFolder(dirPath)
For Each fsoFile In fsoFolder.Files
If Right(fsoFile.name, 4) = ".mdb" Then
je.CompactDatabase _
SourceConnection:="Data Source=" & dirPath & "\" & fsoFile.name, _
DestConnection:="Data Source=" & dirPath & fsoFile.name & "temp.mdb; "
tempName = fsoFile.name
fsoFile.Delete
Name (dirPath & tempName & "temp.mdb") As (dirPath & tempName)
End If
Next fsoFile
Else
MsgBox "Invalid Path"
End If
You can use Name as I have to rename files.
Mordja