Consulting

Results 1 to 4 of 4

Thread: Solved: VBA Compact and Repair

  1. #1
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location

    Solved: VBA Compact and Repair

    Can someone tell me the VBA code to compact an Access database. This will be done from Excel.

    I set it to do this automatically when it closes, but it doesn't seem to trigger when Excel opens and closes the database.

    Thanks

    Jacob

  2. #2
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Mr Jacob,

    Have you tried using dbengine.compactdatabase?

    untested:[vba] Dim Acc As Object
    Set Acc = CreateObject("access.application")
    Acc.DBEngine.CompactDatabase "C:\YourDB.mdb", "C:\tmp.mdb"
    Acc.Quit
    Set Acc = Nothing
    Kill "C:\YourDB.mdb"
    Name "C:\tmp.mdg" As "C:\YourDB.mdb"[/vba]Matt

  3. #3

  4. #4
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Not sure if this is for Office 2003 only, but I have used
     oACC = CreateObject("Access.Application")
     oACC.CompactRepair(LogFile:=True,SourceFile:=cMDB,DestinationFile:=cBkup)
    Stan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •