Compact and repair under program control?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Don Wiss

    Compact and repair under program control?

    I'm doing more putting of data into Access using Excel VBA. After I've done
    I like to Compact and Repair the database. I'd like to be able to do this
    from VBA. Can I?

    Don <www.donwiss.co m(e-mail link at home page bottom).
  • Chris O'C via AccessMonster.com

    #2
    Re: Compact and repair under program control?

    You don't mention what version of Access you're using, but in Access 2002 and
    later, the command is:

    CompactRepair SourceFilePath, DestinationFile Path

    To use this command in Excel, either set a reference to the Microsoft Access
    Object Library or use late binding.

    Chris
    Microsoft MVP


    Don Wiss wrote:
    >I'm doing more putting of data into Access using Excel VBA. After I've done
    >I like to Compact and Repair the database. I'd like to be able to do this
    >from VBA. Can I?
    >
    >Don <www.donwiss.co m(e-mail link at home page bottom).
    --
    Message posted via AccessMonster.c om


    Comment

    • Don Wiss

      #3
      Re: Compact and repair under program control?

      On Sun, 18 May 2008, "Chris O'C via AccessMonster.c om" <u29189@uwewrot e:
      >Don Wiss wrote:
      >>I'm doing more putting of data into Access using Excel VBA. After I've done
      >>I like to Compact and Repair the database. I'd like to be able to do this
      >>from VBA. Can I?
      >You don't mention what version of Access you're using, but in Access 2002 and
      >later, the command is:
      >
      CompactRepair SourceFilePath, DestinationFile Path
      >
      >To use this command in Excel, either set a reference to the Microsoft Access
      >Object Library or use late binding.
      I'm using Access 2002. Can the Source and Destination file paths be the
      same? I connect to the database using DAO 3.6. Normally I would use execute
      to execute some command. As I would already be tied to the file I don't see
      why I would be giving it a path.

      Don <www.donwiss.co m(e-mail link at home page bottom).

      Comment

      • Chris O'C via AccessMonster.com

        #4
        Re: Compact and repair under program control?

        The source and destination files can't be the same. You should close the db
        before compacting it. Once it's compacted, delete the source file (or rename
        it if you want to test it to be sure it's correct), then rename the
        destination file as the source file. You have to give the path in your code
        because Access isn't a very good guesser. That's why the SourceFilePath and
        DestinationFile Path are required parameters for the CompactRepair function.

        Chris
        Microsoft MVP


        Don Wiss wrote:
        >I'm using Access 2002. Can the Source and Destination file paths be the
        >same? I connect to the database using DAO 3.6. Normally I would use execute
        >to execute some command. As I would already be tied to the file I don't see
        >why I would be giving it a path.
        >
        >Don <www.donwiss.co m(e-mail link at home page bottom).
        --
        Message posted via AccessMonster.c om


        Comment

        Working...