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

LVL 3
FordraidersAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.