Kill Statement and Error 70 when trying to delete PDF file

atreusch

New member
Local time
Today, 03:47
Joined
Dec 26, 2010
Messages
2
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.
 
My first thought here is that these lines

KillProcess "acrobat"
psFillBrowserWithDefaultPDF
Kill (sSelectedFile)

are happening too quickly, try putting a sleep or some type of wait after the KillProcess, 1 second should be enough, the thought is that the process hasn't terminated yet and you're trying to delete the file but it is still opened by the pdf browser.
 
Thanks... I tried that but no go. However, I'm now using FILESTRUCT API and it seems to work. Thanks
 

Users who are viewing this thread

Back
Top Bottom