jueves, 8 de septiembre de 2011

VBScript for compact Access Database

This script compact an Access Database, without the needed of having an Access installation on your Operating System.

Only replace FULLPATHFILENAME and FULLPATHFILENAME2 for original database and temporal database for compacting.

Ex: c:\database.mdb, c:\database_compacted.mdb

Sub Main()
Set Engine = CreateObject("JRO.JetEngine")
On Error Resume Next
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=FULLPATHFILENAME", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=FULLPATHFILENAME2"
If Err.Number <> 0 Then
Err.Clear
Else
Set fso = CreateObject("Scripting.FileSystemObject")
fso.DeleteFile "FULLPATHFILENAME"
fso.MoveFile "FULLPATHFILENAME2", "FULLPATHFILENAME"
Set fso = Nothing
End If
Set Engine = Nothing
End Sub

No hay comentarios:

Publicar un comentario