Using the following code, copied almost exactly from the MSDN libraby, I'm trying to compact an Access 97 database after adding a bunch or records:
It acts like it's working but if I try to open the database afterwards I get an Unrecognized database format 'MyData.mdb' error and the database is shot.
What am I missing in this?
Code:
Sub JROCompactDatabase()
Dim je As New JRO.JetEngine
' Make sure there isn't already a file with the
' name of the compacted database.
If Dir("NewMyData.mdb") <> "" Then Kill "NewMyData.mdb"
' Compact the database
je.CompactDatabase "Data Source=MyData.mdb;", _
"Data Source=NewMyData.mdb;"
' Delete the original database
Kill "MyData.mdb"
' Rename the file back to the original name
Name "NewMyData.mdb" As "MyData.mdb"
End Sub
What am I missing in this?