I'm developing a case management program in ms access 2010. One process requires that the program delete a PDF file. A command button runs the following code:
Private Sub cmdDeleteSelectedFile_Click()
Dim sSelectedFile As String
sSelectedFile = DLookup("txtScansTemp", "tblAdminGlobal_nwk") & Me.lstDocumentsForProcessing.Column(1)
KillProcess "acrobat"
psFillBrowserWithDefaultPDF
Kill (sSelectedFile)
CurrentDb.Execute "Delete * From tblOfficeDocumentManagementListFiles_loc Where tblOfficeDocumentManagementListFiles_loc.lngID = " & Me.lstDocumentsForProcessing
Call FillTableWithFileNames
Me.lstDocumentsForProcessing.Requery
' psFillBrowserWithDefaultPDF
On Error GoTo 0 Exit Sub
cmdDeleteSelectedFile_Click_Error: If Err.Number = 70 Then Resume Next Kill (sSelectedFile)
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdDeleteSelectedFile_Click of VBA Document Form_frmOfficeDocumentManagement"
End If
End Sub
I get the error "70 Access Denied" on the following line: Kill (sSelectedFile). However, when I click the end button in the message box and run the code a second time the file is deleted without further errors. For reference the kill function is part of fso and so I am unable to trap the error in ms access. The files in the directory I am deleting are not protected. also I am displaying the documents on the ms access form using the native ms access 2010 web control.
Any ideas? Thanks in advance.
Private Sub cmdDeleteSelectedFile_Click()
Dim sSelectedFile As String
sSelectedFile = DLookup("txtScansTemp", "tblAdminGlobal_nwk") & Me.lstDocumentsForProcessing.Column(1)
KillProcess "acrobat"
psFillBrowserWithDefaultPDF
Kill (sSelectedFile)
CurrentDb.Execute "Delete * From tblOfficeDocumentManagementListFiles_loc Where tblOfficeDocumentManagementListFiles_loc.lngID = " & Me.lstDocumentsForProcessing
Call FillTableWithFileNames
Me.lstDocumentsForProcessing.Requery
' psFillBrowserWithDefaultPDF
On Error GoTo 0 Exit Sub
cmdDeleteSelectedFile_Click_Error: If Err.Number = 70 Then Resume Next Kill (sSelectedFile)
Else
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdDeleteSelectedFile_Click of VBA Document Form_frmOfficeDocumentManagement"
End If
End Sub
I get the error "70 Access Denied" on the following line: Kill (sSelectedFile). However, when I click the end button in the message box and run the code a second time the file is deleted without further errors. For reference the kill function is part of fso and so I am unable to trap the error in ms access. The files in the directory I am deleting are not protected. also I am displaying the documents on the ms access form using the native ms access 2010 web control.
Any ideas? Thanks in advance.