Code to compact Access 2010 database under vb.net

Morning,

I am developing an application in VB.Net, I'm using an access 2010 database to store my data for the application.

I would like my application to compact the database when the user clicks a button on my windows form.

I've found several things on the net for an Access 2003 database (.mdb), but I am wondering if the same applies to an access 2010 database (.accdb).

A sample of the code that I found on the net is below:

'COMPACT DATABASE

    Private Sub CompactDB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles

    CompactDB.Click
        Dim JRO As JRO.JetEngine
        JRO = New JRO.JetEngine

        'The first source is the original, the second is the compacted database under an other name.
        JRO.CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\VSoft\AppMiss\NewAppDB.mdb; Jet OLEDB:Engine Type=5", "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Program Files\VSoft\AppMiss\NewAppDBComp.mdb; JetOLEDB:Engine Type=5")

        'Original (not compacted database is deleted)
        File.Delete("C:\Program Files\VSoft\AppMiss\NewAppDB.mdb")

        'Compacted database is renamed to the original databas's neme.
        Rename("C:\Program Files\VSoft\AppMiss\NewAppDBComp.mdb", "C:\Program Files\VSoft\AppMiss\NewAppDB.mdb")

        'User notification
         MsgBox("The database was compacted successfully")

     End Sub

Open in new window


Can this code be used with .accdb files, by just changing the extension from .mdb to .accdb? Or would the code differ for Access 2010 versions?

Kindly advise.

Regards,
N
LVL 1
KevinAsked:
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.

Rey Obrero (Capricorn1)Commented:
i don't think you can use JRO for .accdb versions of access db..

try something like this
Dim dbe As New Microsoft.Office.Interop.Access.Dao.DBEngine

dbe.CompactDatabase("C:\folder\yourDB.accdb",  "C:\folder\yourDB_New.accdb", , , ";pwd=<yourDB password>")

'Rename the old file with the date and time appended, then copy the new repaired file back.

Rename("C:\folder\yourDB.accdb", "c:\folder\yourDB_Old " & Format(Now(), "yyyymmdd hhnnss") & ".accdb")

Rename("C:\folder\yourDB_New.accdb",  "C:\folder\yourDB.accdb") 

.

Open in new window

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
KevinAuthor Commented:
Thanks Rey, Ill give it a try.

Can you also confirm something for me please. The workstation where the application and database sit will not have office 2010 installed. I've been reading that I can installed  the 'Microsoft Access Database Engine 2010 Redistributable' package. But some posts say I still need to have office 2010 installed and some posts say i dont.

Are you able to confirm?

Kindly advise,

Regards
N
0
KevinAuthor Commented:
Thanks Rey.
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.