EnglischerZauberer
EnglischerZauberer

Reputation: 237

RmDir - Path/File Access Error VBA

I'm attempting to delete a folder using the RmDr function in VBA. On executing the snippet below, I get the following error:

"Path/File Access Error".

    'Delete HTML Folder
    If (DirExists(fileDir)) Then
        Kill fileDir & Chr(92) & "*.*"
        RmDir fileDir
    End If

The documentation reads:

Remarks An error occurs if you try to use RmDir on a directory or folder containing files. Use the Kill statement to delete all files before attempting to remove a directory or folder.- https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/rmdir-statement

My code already deletes all contents of the folder successfully, however I am still receiving this error.

Does any one have any experience with this error?

Upvotes: 1

Views: 2683

Answers (1)

EnglischerZauberer
EnglischerZauberer

Reputation: 237

As you all said, it doesn't seem to an issue with the code. I looked into it a bit more and seemed to be an issue with my Macro settings in Office.

In Access, I went to File >> Options >> Trust Center >> Trust Center Settings and set Macros to enabled.

Now the target folder deletes successfully.

Thanks for the help.

Upvotes: 1

Related Questions