2

当我尝试使用 FSO.DeleteFile 删除文件时,我收到“错误 70 权限被拒绝”。当我尝试使用 Kill 命令时,我收到“错误 75 路径/文件访问错误”。我对该文件夹具有读/写权限,尽管它位于网络驱动器而不是本地驱动器上。

这是我的代码:

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
4

1 回答 1

2

我以前遇到过这个。我试图删除的文件被隐藏了。如果不先取消隐藏,您无法以编程方式删除隐藏文件。在终止文件之前尝试将此子添加到您的代码中。

Sub unhideFile(filename as string)
    If Len(Dir$(filename, vbHidden))>0 then
        SetAttr filename, vbNormal
    End If
End Sub
于 2014-01-22T13:13:09.043 回答