Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Posts
    74

    Unanswered: compact and repair database

    hi

    how can i auto repair and compact my database each time the database is closed???

    pls advice
    nono

  2. #2
    Join Date
    Oct 2003
    Location
    Roanoke, Va
    Posts
    445

    Smile Re: compact and repair database

    Originally posted by damnnono_86
    hi

    how can i auto repair and compact my database each time the database is closed???

    pls advice
    nono
    There are some on the forum who regularly do this in code and can clue you in as to the whens and wherefors but until then for your viewing pleasure, here is the Help File text. Incidentally, this is run through the Application object (Application.CompactRepair).

    CompactRepair Method

    Compacts and repairs the specified database (.mdb) or Microsoft Access project (.adp) file. Returns a Boolean; True if the process was successful.

    expression.CompactRepair(SourceFile, DestinationFile, LogFile)

    expression Required. An expression that returns one of the objects in the Applies To list.

    SourceFile Required String. The full path and filename of the database or project file to compact and repair.

    DestinationFile Required String. The full path and filename for where the recovered file will be saved.

    LogFile Optional Boolean. True if a log file is created in the destination directory to record any corruption detected in the source file. A log file is only created if corruption is detected in the source file. If LogFile is False or omitted, no log file is created, even if corruption is detected in the source file.

    Remarks
    The source file must not be the current database or be open by any other user, since calling this method will open the file exclusively.

    Example
    The following example compacts and repairs a database, creates a log if there's any corruption in the source file, and returns a Boolean value based on whether the recovery was successful. For the example to work, you must pass it the paths and file names of the source and destination files.

    Function RepairDatabase(strSource As String, _
    strDestination As String) As Boolean
    ' Input values: the paths and file names of
    ' the source and destination files.

    ' Trap for errors.
    On Error GoTo error_handler

    ' Compact and repair the database. Use the return value of
    ' the CompactRepair method to determine if the file was
    ' successfully compacted.
    RepairDatabase = _
    Application.CompactRepair( _
    LogFile:=True, _
    SourceFile:=strSource, _
    DestinationFile:=strDestination)

    ' Reset the error trap and exit the function.
    On Error GoTo 0
    Exit Function

    ' Return False if an error occurs.
    error_handler:
    RepairDatabase = False

    End Function

    Good Luck.

    Gregg

  3. #3
    Join Date
    Nov 2003
    Posts
    5
    U can select the "Compact on close" option in Tools/Options - General tab.

    HTH

    M.

  4. #4
    Join Date
    Oct 2003
    Posts
    66
    Don't know if you have multiple users using the database but if so this might be a problem since i think evryone has to be logged out of database. If you do have multi user evironment you might want to do the compact and repair using a batch file run from a sever after a nightly backup. I also suggest always perform the compact and repair only after a back up has been done.

    Just thought i would give you somehtings to think about.

Posting Permissions

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