Search Tools Links Login

Compact Microsoft Access Database Through ADO


Visual Basic 6, or VB Classic

Although ADO specification does not provide objects to compact Microsoft Access databases, this capability can be achieved by using the ADO extension: Microsoft Jet OLE DB Provider and Replication Objects (JRO). This capability was implemented for the first time in the JET OLE DB Provider version 4.0 (Msjetoledb40.dll) and JRO version 2.1 (Msjro.dll). These DLL files are available after the install of MDAC 2.1. You can download the latest version of MDAC from the following Web site:

Original Author: Roni Saar

Inputs

the file you want to compact

Side Effects

No Side Effects

Code

Public Function CompactDatabase(strFileName As String) As Boolean
Dim objJro As jro.JetEngine
Dim objFileSystem As FileSystemObject
Dim strTmpFileName As String
On Error GoTo EXIT_PROC

Set objFileSystem = CreateObject("Scripting.FileSystemObject")
strTmpFileName = objFileSystem.GetSpecialFolder(TemporaryFolder).Path & "" & objFileSystem.GetFileName(strFileName)
Set objJro = New jro.JetEngine

objJro.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFileName, _
       "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strTmpFileName & ";Jet OLEDB:Engine Type=5"

objFileSystem.CopyFile strTmpFileName, strFileName
objFileSystem.DeleteFile strTmpFileName, True

CompactDatabase = True

EXIT_PROC:

Set objFileSystem = Nothing
Set objJro = Nothing
End Function

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 113 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.