0

The below code works great when you call an unsecured database from another database. But I am trying to compact an .mdb in Office 2013 that has user-level security (.mdw).

If I try the below code with an .mdb with .mdw and try and compact the open database I get error 3045, file in use.

If I try the below code with an .mdb with .mdw and try and compact a different database I get error 3033, do not have necessary permissions.

If anyone has a solution that would be wonderful. Thank you in advance!

Public Function CompactAndRepairAccessDB()

    Dim Acc As Object
    Set Acc = CreateObject("access.application")

    Dim dbPath As String, dbPathX As String
    dbPath = "\\servername\database.mdb"
    dbPathX = "\\servername\databaseTEMP.mdb"

    Acc.DBEngine.CompactDatabase dbPath, dbPathX
    Acc.Quit
    Set Acc = Nothing
    Kill dbPath
    Name dbPathX As dbPath

End Function

1 Answer 1

0

According to the Microsoft documentation, the CompactDatabase method takes a password as the last parameter.

CompactDatabase(SrcName, DstName, DstLocale, Options, password)

This would be the admin password for the database if there are multiple users.

BTW, you cannot compact the current database from code. You can create a small Access database to compact your other databases with though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.