Results 1 to 7 of 7
  1. #1
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Compact and Repair Code? (2002/2003)

    Is there a way to execute the compact and repair facility from a command button in code, and if so is this advisable? I find it convenient to perform this action, but to do it I have to open the database in the mode where the menu appears whereas in the normal application I turn that menu off so that the users can't muck around with it.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Compact and Repair Code? (2002/2003)

    You can put the following code in the On Click event of a command button, or in the On Action code of a custom toolbar button:

    Application.CommandBars("Menu Bar").FindControl(ID:=2071, Recursive:=True).accDoDefaultAction

  3. #3
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Compact and Repair Code? (2002/2003)

    Hans -- you are an absolute wonder -- it took you exactly one minute and eleven seconds to answer my query -- unbelievable!!

    Thanks again, and I'll give it a try.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Compact and Repair Code? (2002/2003)

    More like 11 minutes <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Compact and Repair Code? (2002/2003)

    Hi Hans

    1. Will this work in a2k?
    2. Is this C & R for the FE?
    3. If so, how would C & R the BE from the FE?

    Thanks, John

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Compact and Repair Code? (2002/2003)

    1) It wouldn't take more than 1 minute to check in Access 2000, would it? According to General - Compact the Current Database from Code on the Access Web, it works in Access 2000 too.

    2) Yes, obviously - the code simply invokes the menu command

    3) Access can't compact another database than the current one to itself. You'd have to compact the BE to a new database, then delete the old BE and rename the new one. (In fact, this is what Access does for the current database too, but the steps are hidden). You can use the DAO method CompactDatabase for this, and the old VB instructions Kill and Name. Look them up in the VBA help, or search Google for CompactDatabase.

  7. #7
    Bronze Lounger
    Join Date
    Feb 2001
    Location
    Escondido, California, USA
    Posts
    1,458
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Compact and Repair Code? (2002/2003)

    11 minutes is still a record breaker as far as I'm concerned! Thanks again.

Posting Permissions

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