Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  

Compact and repair

Recommended Posts


Boas malta

Tudo bem?

Qual o código para fazer o compact and repair de um access, a partir do módulo vba do excel.


Share this post

Link to post
Share on other sites

Estive pesquisando algo para lhe ajudar.. espero qeu isso ajude.

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, _

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

' Return False if an error occurs.
    RepairDatabase = False

End Function

Public Sub teste()
Dim strSource As String
Dim strDestination As String
strSource = "e:\arquivos\igor\hemocentro\cópia de duplicidade.mdb" 'altere o caminho
strDestination = "e:\arquivos\igor\hemocentro\cópia de duplicidade.mdb" 'altere o camino

RepairDatabase strSource, strDestination
End Sub


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.