README.md

December 5, 2022 ยท View on GitHub

Repair and Compact an Access Database using JRO

Description

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

More Info

Submitted On
ByN/A
LevelIntermediate
User Rating4.0 (8 globes from 2 users)
CompatibilityVB 5.0, VB 6.0, VBA MS Access
CategoryDatabases/ Data Access/ DAO/ ADO
WorldVisual Basic
Archive File

Source Code

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