Donnachaidh
Donnachaidh

Reputation: 159

MS Access 2007 VBA FSO.DeleteFile Error 70 Permission Denyed

When I try to delete a file with FSO.DeleteFile I get 'Error 70 Persmission Denyed'. When I try to use the Kill command I get 'Error 75 Path/File access error'. I have read/write privileges to the folder, though it is on a network drive not a local drive.

Here's my code:

Private Sub DeleteFileButton_Click()
On Error GoTo Err_DeleteFileButton_Click

    Dim FileLocation As String
    Dim strSQL As String
    FileLocation = DLookup("AttachmentLink", "dbo_tbl208Attachments", "ATID = " & Me.lstFiles.Column(1))
    strSQL = "DELETE FROM dbo_tbl208Attachments WHERE ATID = " & Me.lstFiles.Column(1)
    With New Scripting.FileSystemObject
        .DeleteFile FileLocation
End With
    'Kill FileLocation
    CurrentDb.Execute strSQL, dbFailOnError
    MsgBox "File has been deleted"

Exit_DeleteFileButton_Click:
    Exit Sub

Err_DeleteFileButton_Click:
        MsgBox Err.Number & " - " & Err.Description
        Resume Exit_DeleteFileButton_Click
End Sub

Upvotes: 2

Views: 1625

Answers (1)

RubberDuck
RubberDuck

Reputation: 12728

I've run into this before. The file I was trying to delete was hidden. You can't programmaticly delete a hidden file without unhiding it first. Try adding this sub to your code before killing the file.

Sub unhideFile(filename as string)
    If Len(Dir$(filename, vbHidden))>0 then
        SetAttr filename, vbNormal
    End If
End Sub

Upvotes: 2

Related Questions