• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

Access Compact and Repair: Several Databases

vb.net 2003
access 2003

What I have:
Routine that is compact and repairing an access database

What I need:
I have several Databases I wantto Compact and Repair  at Once.
All in the same folder; But Only Specific ones;
C:\PROGRAM FILES\DATA

MyData.mdb
Items.mdb
Information.mdb
Sales.mdb
Request.mdb

I need to create a loop that will compact and repair them one at a time


Thanks
fordraiders


Public Sub CompactAccessDBSkuREnd(ByVal strConnectionString As String, ByVal strMDBFilename As String)
        ' changed on 11/19/2007
        Dim oParams As Object()
        Dim strMe As String
        If System.IO.File.Exists("C:\PROGRAM FILES\DATA\Request.mdb") Then
            strMe = FileLen("C:\PROGRAM FILES\DATA\Request.mdb")
            Dim jro As JRO.JetEngine
            jro = New JRO.JetEngine
            Try
                jro.CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\PROGRAM FILES\DATA\Request.mdb", _
                "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\PROGRAM FILES\DATA\TempDataMdb.mdb;Jet OLEDB:Engine Type=5")
                System.IO.File.Delete(strMDBFilename)
                System.IO.File.Move("C:\PROGRAM FILES\DATA\TempDataMdb.mdb", strMDBFilename)
                ' Clean up (Just in case)
                System.Runtime.InteropServices.Marshal.ReleaseComObject(jro)
                jro = Nothing
            Catch Ex As Exception
                MessageBox.Show("Request.mdb Is Already Open. Please close and try again")
            End Try
            '    End If
        End If
    End Sub

Open in new window

0
Fordraiders
Asked:
Fordraiders
1 Solution
 
Bob LearnedCommented:
You could create a list:

Dim databaseList As String() = {"MyData.mdb", "Items.mdb", "Information.mdb", "Sales.mdb", "Request.mdb"}

For Each databaseName As String In databaseList
   CompactAccessDBSkuREnd(connectionString, databaseName)
Next databaseName

Bob
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now