当我尝试使用 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