Results 1 to 8 of 8
  1. #1
    kdbailey is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    228

    Compact and Repair Access 2007 Through VBA Code

    I am looking for a way to compact and repair database through vba. On Access 2003 I was able to "click" by navigating the toolbars through code. I do not believe that is an option anymore. Does anybody know how to do this?

    I also have a quick access button setup for compact and repair if there a way to hit the quick access button through code.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    I Binged 'access 2007 vba compact and repair' but didn't find much.

    http://www.access-programmers.co.uk/...d.php?t=160025
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I take it you don't want to compact the database every time you close it but just sort of an 'on demand' type process?

    If you do want to compact it every time it's closes you can set that through your options.

    If you want it to be on demand you can look here:

    http://rogersaccessblog.blogspot.com...nt-access.html

  4. #4
    kdbailey is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    228
    Quote Originally Posted by June7 View Post
    I Binged 'access 2007 vba compact and repair' but didn't find much.

    http://www.access-programmers.co.uk/...d.php?t=160025
    Same, I looked about a month ago but basically found a lot of threads asking for a solution with not many answers.

  5. #5
    kdbailey is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    228
    Quote Originally Posted by rpeare View Post
    I take it you don't want to compact the database every time you close it but just sort of an 'on demand' type process?

    If you do want to compact it every time it's closes you can set that through your options.

    If you want it to be on demand you can look here:

    http://rogersaccessblog.blogspot.com...nt-access.html
    Ya, I am looking for a more on demand type deal. I do a nightly update of all of our databases and am looking for the code to compact following the updates. Apparently this blog is blocked here at work, so I'll have to take a look when I get home.

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    If you're looking to do a nightly update that is independent of someone clicking a button that's fairly easy.

    You'd just have to have an access database (unrelated to any of your live databases) with an main form. in the ON OPEN event of that form you can have it run code that will compact and repair any number of external databases then close itself.

    Let's say you have a database 'LiveDatabase.accdb' or '.mdb' that you want compacted nightly.

    On your server (or other workstation that is left on) you can have a scheduled task to open your database that performs the maintenance. Let's call that database 'maintenance.accdb' or '.mdb'

    You schedule a task on the host computer to pen maintenance.accdb every night at 10pm (assuming it's a regular 9-5 office and nobody will be in the database at that time)
    when maintenance.accdb is opened it compacts and repairs LiveDatabase.accdb to the filename LiveDatabase-Updated.accdb (or whatever name you specify)
    Copies the LiveDatabase.accdb to a 'backup' folder and removes the original copy from the working directory
    Renames LiveDatabase-Updated.accdb to LiveDatabase.accdb
    part of the code can also be to close maintenance.accdb when all the code is done running.

    Just be warned, I don't believe the compact/repair will work if people remain in the application when they go home so you'd either have to terminate connections to the database programmatically (if they exist) or have a way to kick people off.

  7. #7
    naeemahmad is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Location
    Riverside, USA
    Posts
    46
    Regarding users in the db during compact/repair..

    When you compact a Microsoft Access file located on a volume that uses the NTFS file system, Access removes the existing file and replaces it with the compacted file.
    It then applies the default file permissions to the new file. If the file is an Access database, use Access user-level security instead of file-level permissions.
    Otherwise, use folder permissions. For more information about the NTFS file system and folder permissions, see Windows Help.


    You must have Open/Run and Open Exclusive permissions for an Access database in order to compact and repair it, therefore 'rpeare' is correct, you should not have any users in the sysyem during this process.

    http://office.microsoft.com/en-us/ac...010341740.aspx

    Naeem~

  8. #8
    kdbailey is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2012
    Posts
    228
    I appreciate the input, I actually have figured out how to accomplish what I was looking for.

    As far as ensuring people are out of the database, I wrote a simple, easy-to-understand function that kicks people out for inactivity for any specified amount of time. If anybody is interested in that code I can post it.

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

Similar Threads

  1. Automating compact/Repair and backup of BE
    By togo in forum Programming
    Replies: 1
    Last Post: 12-27-2012, 03:29 PM
  2. Replies: 3
    Last Post: 05-04-2012, 12:04 AM
  3. Compact & Repair, Will I Run Into Problems?
    By robsworld78 in forum Access
    Replies: 1
    Last Post: 01-10-2012, 05:11 PM
  4. Compact and repair on close
    By colotazzman in forum Access
    Replies: 2
    Last Post: 05-20-2010, 02:04 PM
  5. MS-Access 2007 - Compact & Repair how?
    By techexpressinc in forum Access
    Replies: 2
    Last Post: 03-05-2009, 02:12 PM

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