[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3695
  • Last Modified:

revise compact and repair vba from another accdb for vba 2010

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
0
Fordraiders
Asked:
Fordraiders
  • 2
1 Solution
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
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

0
 
FordraidersAuthor Commented:
Thanks worked fine.
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

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