Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003

    Unanswered: how to compact mdb programmatically?

    anyone knows how to compact another mdb programmatically?
    is it possible to compact the mdb itself programatically?
    thank you
    hendra gunadi

  2. #2
    Join Date
    May 2004
    The Netherlands
    This is the way how we do it:

    Private Sub cmdCompactDatabase_Click()
    Dim Response As VbMsgBoxResult
    Dim strFullDBName As String
    Dim strFullDBNameNew As String

    'Prompt the user for compacting the back-end database
    Response = MsgBox("Weet u zeker, dat u de back-end database wilt comprimeren?", _
    vbQuestion + vbYesNo, _
    If Response = vbYes Then
    'Determine the fullname of the database and compact the database
    strFullDBName = "TargetDB.mdb"
    strFullDBNameNew = Left(strFullDBName, Len(strFullDBName) - 4) & "_New.mdb"
    Application.Screen.MousePointer = 11
    DBEngine.CompactDatabase strFullDBName, strFullDBNameNew

    With New FileSystemObject
    'Delete the current databasefile
    .DeleteFile strFullDBName, True
    'Rename the new file to the name of the "old" database file
    Name strFullDBNameNew As strFullDBName
    End With
    Application.Screen.MousePointer = 0
    End If
    End Sub

    Note: For this sub, you need to make a reference to 'Microsoft Scripting Runtime'

  3. #3
    Join Date
    Jan 2012

    Backend error


    I tried your code and Its working good, but I have set a Database pwd in backend file. So, it repiles me as "Not a valid password". can you help to resolve it because it is important to set backend password.

    many thanks.

Posting Permissions

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