Compact backend database, taking logged in users into account on Exit

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neelsfer
    Contributor
    • Oct 2010
    • 547

    #1

    Compact backend database, taking logged in users into account on Exit

    I currently use the following code to manually compact a backend database from a desktop icon now and then, when it gets a bit "bloated"
    Code:
    "C:\Program Files\Microsoft Office\Office12\MSACCESS.EXE" "C:\pisprg\Pisdatav2.accdb" /compact
    It would be very nice to add vba code to the application's "exit" button, that will look at the linked BE files and whether another pc is logged into the BE (and warn me), and then compact it accordingly.
    I assume this can only happen when nobody is logged into the system from another pc, as that is how i currently do it.
    Any suggestions?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You can check for the existence of the lock file. Although I've heard that is not completely reliable because sometimes it doesn't delete the lock file when there's no one in the database.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      So many questions today I almost missed this one after it scrolled off the screen :-(

      I've always found it entirely safe to attempt to delete the LDB file of an Access database. A lock file (LDB) is always maintained open by the version of Access using it, so an attempt will only ever succeed when no users currently have the MDB or ACCDB open. Clearly, before attempting to delete it, determine that it even exists (as Rabbit said), but if it does exist then try to delete it before assuming the (M/ACCDB) file is actually in use.

      PS. Dir() can tell you if a file exists and Kill will attempt to erase it for you. We'll assume you know enough to continue unless you indicate otherwise.
      Last edited by NeoPa; Jan 9 '13, 02:01 AM. Reason: Added PS.

      Comment

      Working...