VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Repair and Compact an Access Database using JRO


Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

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!!

Rate Repair and Compact an Access Database using JRO

Option Explicit




'Must have reference to Microsoft Jet And Replication Objects x.x Library 


Public Sub CompactDB(DBName As String)



Dim jr As jro.JetEngine

Dim strOld As String, strNew As String

Dim x As Integer



Set jr = New jro.JetEngine



strOld = DBName

x = InStrRev(strOld, "\")

strNew = Left(strOld, x)

strNew = strNew & "chngMe.mdb"



'Use Engine Type = 4 for Access 97, Engine Type = 5 for Access 2000

jr.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strOld,
_

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strNew & ";Jet
OLEDB:Engine Type=4"



Kill strOld

DoEvents

Name strNew As strOld



Set jr = Nothing



End Sub


Download this snippet    Add to My Saved Code

Repair and Compact an Access Database using JRO Comments

No comments have been posted about Repair and Compact an Access Database using JRO. Why not be the first to post a comment about Repair and Compact an Access Database using JRO.

Post your comment

Subject:
Message:
0/1000 characters