I have done this. sDBPath and sDBNameBak come from a table earlier
Public Sub JROCompactDatabase()
Dim je As New JRO.JetEngine
Dim dbName As String
Dim dbBakName As String
On Error GoTo ERRH
dbName = sDBPath & sDBName
dbBakName = sDBPath & sDBNameBak
If Dir(dbBakName) “” Then Kill dbBakName
Name dbName As dbBakName
je.CompactDatabase “Data Source=” & dbBakName & “;Jet OLEDB:Engine Type=4;”, “Data Source =” & dbName & “;Jet OLEDB:Engine Type=4;”
Set je = Nothing
I have developed a quick and easy app for tracking Computer Equipment within my organization.
Here is some quick code that will:
1. Create a new Compacted Database
2. Delete the old Backup
3. Create a new Backup from the original database
If mCompactDatabase = 1 Then
cmdCancel.Enabled = False
Command1.Caption = “&Please Wait …”
DBEngine.CompactDatabase “C:INVENTDATAINVENT.MDB”, “C:INVENTDATAINVNEW.MDB”, “”, dbEncrypt
Name “C:INVENTDATAINVENT.MDB” As “C:INVENTDATAINVENT.BAK”
Name “C:INVENTDATAINVNEW.MDB” As “C:INVENTDATAINVENT.MDB”
Command1.Caption = “Process &Complete”
Hope you can follow the logic (it is pretty simple) and I sure hope this helps.
Thank you and have a great day.
Do not hesitate to contact me if you have any questions on this.
Gary R. Primrose