Home All Groups Group Topic Archive Search About

Compacting an access db from vb

Author
3 Aug 2006 7:57 AM
reidarT
How can I copact and repair an accesws db from VB?
reidarT

Author
3 Aug 2006 9:20 AM
Simon Verona
I use JRO (add a reference to Interop.JRO.Dll) and the following code

Private Sub CompactDatabase(ByVal Directory As String, ByVal Filename As String)    ' Directory is the directory that contains the access database

' Compact Access Database

Dim jro As JRO.JetEngine

jro = New JRO.JetEngine

If System.IO.File.Exists(Directory & "\New" & Filename) Then System.IO.File.Delete(Directory & "\New" & Filename) ' Check that there is no file called New + Filename

Try

jro.CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Directory & "\" & Filename, _

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Directory & "\New" & Filename & ";Jet OLEDB:Engine Type=5")  ' Compacts the database into a new file beginning with "new"

System.IO.File.Delete(Directory & "\" & Filename) ' Deletes the original database

System.IO.File.Copy(Directory & "\New" & Filename, Directory & "\" & Filename, True) ' Copys across the New over the original

System.IO.File.Delete(Directory & "\New" & Filename)  ' Delete the New database

Catch

End Try

End Sub



Regards
Simon

--
================================
Simon Verona
Dealer Management Service Ltd
Stewart House
Centurion Business Park
Julian Way
Sheffield
S9 1GD

Tel: 0870 080 2300
Fax: 0870 735 0011

Show quoteHide quote
"reidarT" <rei***@eivon.no> wrote in message news:O7hs3JttGHA.4852@TK2MSFTNGP02.phx.gbl...
> How can I copact and repair an accesws db from VB?
> reidarT
>
>