Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with JRO CompactDatabase method

Status
Not open for further replies.

jbradley

Programmer
Sep 7, 2001
248
0
0
US
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:
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(&quot;NewMyData.mdb&quot;) <> &quot;&quot; Then Kill &quot;NewMyData.mdb&quot;

   ' Compact the database
   je.CompactDatabase &quot;Data Source=MyData.mdb;&quot;, _
      &quot;Data Source=NewMyData.mdb;&quot;

   ' Delete the original database
   Kill &quot;MyData.mdb&quot;

   ' Rename the file back to the original name
   Name &quot;NewMyData.mdb&quot; As &quot;MyData.mdb&quot;

End Sub
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?
 
Need to specify the provider like such:

je.CompactDatabase &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\datafiles\myData.mdb&quot;, &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\datafiles\NewMyData.mdb;Jet OLEDB:Engine Type=5&quot;


Mark
 
Thanks, Mark! That did the trick, although I had to use Type=4 with my Access 97 database.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top