Results 1 to 10 of 10
  1. #1
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question Run Companct and Repair


    I am looking for a way to have a compact and repair run by the click of a button instead of having to use the option on the menu. Any suggestions? Thank you!

  2. #2
    Join Date
    May 2010
    Posts
    339
    Code:
    CommandBars("Menu Bar"). _
       Controls("Tools"). _
       Controls("Database utilities"). _
       Controls("Compact and repair database..."). _
       accDoDefaultAction

  3. #3
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Thank you for your help.

  4. #4
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question

    Unfortunately when I tried to use this code I received the following error:

    "You cannot compact the open database by running a macro or Visual Basic code.

    Instead of using a macro or code, click the Microsoft Office Button, point to Manage, and then click Compact and Repair Database."

    Any suggestions?

  5. #5
    Join Date
    May 2010
    Posts
    339
    You have the code behind a standard button?

  6. #6
    Join Date
    May 2010
    Posts
    339
    I just read the part about the OPEN form that is true, it needs to close first. Infact I believe all objects have to be closed.

  7. #7
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Your best bet would be to create a new Shortcut on your Desktop to Compact and Repair the database.

    When you create the shortcut, point it to MSACCESS.EXE instead of your database then do the following:
    Add the path and filename to your database after MSACCESS.EXE
    Add "/compact" after your database path

    Once you're done, you'll end up with a shortcut that points to MSACCESS.EXE like the following:
    "C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "C:\Database\MyDB.mdb" /compact

    Whenever you run that shortcut, it'll Compact and Repair your database for you.

  8. #8
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Well My goal is this. I have a bunch of append queries that run and to keep the DB within the 2GB size constraints I need to run a compact and repair after running a portion of the queries. So what I was going to do is develop a button that would run Query1, Query2, Query3 and then run a compact and repair. This would save me from having to manually run each query and then manually clicking the compact and repair button. The only code I have in the command button is the code you provided above.

    I guess I could just have the command button run the queries and then run the compact and repair myself.

  9. #9
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Hrm,

    You may be out of luck then because it looks like you can't run a Compact and Repair from within the database you're Compacting and Repairing.

    Have you considered splitting the database into two (or three?) separate ones? That would allow you to keep individual file sizes below 2GB fairly easily, unless 99% of all your data is in a single table.

  10. #10
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Yea, splitting up the DB would too much of a hassle for what I am doing. I will just run the compact and repair seperately. Thanks for your help.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Compact and repair on close
    By colotazzman in forum Access
    Replies: 2
    Last Post: 05-20-2010, 02:04 PM
  2. Best Access Repair Utility?
    By syoo in forum Access
    Replies: 6
    Last Post: 01-29-2010, 06:35 AM
  3. Automate Compact and Repair process
    By tracerbullet in forum Security
    Replies: 2
    Last Post: 01-14-2010, 05:12 PM
  4. Error 3167 Compact and Repair
    By jonsuns7 in forum Access
    Replies: 3
    Last Post: 10-27-2009, 08:19 AM
  5. MS-Access 2007 - Compact & Repair how?
    By techexpressinc in forum Access
    Replies: 2
    Last Post: 03-05-2009, 02:12 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums