Advertisement
C_Volume2 Databases/ Data Access/ DAO/ ADO #70634

Repair and Compact an Access Database using JRO

This code will let you repair and compact an Access 97 or 2000 (haven't tested on other versions yet) database. Using JRO, when you call the CompactDatabase function, it automatically repairs the database first. You must have a reference to Microsoft Jet And Replication Objects x.x Library in your project. Also, where I have a DoEvents in the code, there really should be some routine that checks to see when the file is actually deleted. I've tested this on databases that are about 5 megs in size with no problem. If anyone has any ideas (maybe a routine that checks to see when the file is unlocked or deleted), let me now. Thanks and enjoy!!

AI

AI 摘要: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

源代码
original-source
<p>Option Explicit<br>
<br>
</p>
<p>'Must have reference to Microsoft Jet And Replication Objects x.x Library <br>
</p>
<p>Public Sub CompactDB(DBName As String)<br>
<br>
Dim jr As jro.JetEngine<br>
Dim strOld As String, strNew As String<br>
Dim x As Integer<br>
<br>
Set jr = New jro.JetEngine<br>
<br>
strOld = DBName<br>
x = InStrRev(strOld, &quot;\&quot;)<br>
strNew = Left(strOld, x)<br>
strNew = strNew &amp; &quot;chngMe.mdb&quot;<br>
<br>
'Use Engine Type = 4 for Access 97, Engine Type = 5 for Access 2000<br>
jr.CompactDatabase &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; &amp; strOld,
_<br>
&quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; &amp; strNew &amp; &quot;;Jet
OLEDB:Engine Type=4&quot;<br>
<br>
Kill strOld<br>
DoEvents<br>
Name strNew As strOld<br>
<br>
Set jr = Nothing<br>
<br>
End Sub<br>
</p>
原始评论 (3)
从 Wayback Machine 恢复