We help IT Professionals succeed at work.

revise compact and repair  vba from another accdb for vba 2010

Fordraiders
Fordraiders asked
on
vba 2003
access 2003

I ave code here that will compact and repair a database via vba code from another database.


Dim gsDBPath As String
 
 

    gsDBPath = "C:\Program Files\Crs\CartDatabases\"

    Kill gsDBPath + "SapAlternates2.mdb"
'
    DBEngine.CompactDatabase gsDBPath + "SapAlternates.mdb", gsDBPath + "SapAlternates2.mdb"
    Kill gsDBPath + "SapAlternates.mdb"
    Name gsDBPath + "SapAlternates2.mdb" As gsDBPath + "SapAlternates.mdb"


Does this code need to be revised to work in vba 2010... I have not used it yet ?

or better yet.

is the better code for doing this in office 2010 ?

Thanks
fordraiders
Comment
Watch Question

SQL Server Data Dude
BRONZE EXPERT
Most Valuable Expert 2013
Author of the Year 2015
Commented:
Yes, but just because I like making comments like this ... did you try it first?

I pieced together the below function in my Access 2010, and it worked fine.  

Public Function fn_compact_repair()

Dim oApp As Access.Application
Set oApp = Access.Application

oApp.DBEngine.CompactDatabase "C:\portfolio\fooey\db1.mdb", "C:\portfolio\fooey\db2.mdb"
Kill "C:\portfolio\fooey\db1.mdb"
Name "C:\portfolio\fooey\db2.mdb" As "C:\portfolio\fooey\db1.mdb"

End Function

Open in new window

Author

Commented:
Thanks worked fine.
Jim HornSQL Server Data Dude
BRONZE EXPERT
Most Valuable Expert 2013
Author of the Year 2015

Commented:
Thanks for the grade.  Good luck with your project.  -Jim