AirCooledNut
09-21-2012, 08:28 AM
I have a routine that is supposed to delete a file on a network folder. Everytime it executes the KILL command I get a "File not found" error and yet the file is there! :dunno
This is the command I'm using:
Kill !pathname 'Delete the electronic file! which is found here:
...
'Now delete the files!
SysCmd acSysCmdSetStatus, "Deleting electronic files..."
On Error GoTo Err_Execute 'Use our error handling
bError = False 'Set default
Set db = CurrentDb 'Get our [current] database
Set rstErrorTable = db.OpenRecordset("tblDestroy_Electronic_Err") 'Get the table for capturing errors
Set rstFormRecords = Me.FilesToDestroy.Form.Recordset 'Get the records from the subform
With rstFormRecords
.MoveFirst 'Make sure we start at the beginning
Stop 'Testing
Do While Not .EOF 'Loop thru all the records until we hit the end
bErrorFlag = False 'This flag is set to TRUE in the error handler (indicates an error occurred)
Kill !pathname 'Delete the electronic file!
'Update DestroyedDate, DestroyedBy, Witness, and ScanExists fields in tblMasterScans but make no updates to tbl_Project_Locations.
If Not bErrorFlag Then
db.Execute "UPDATE tblMasterScans SET DestroyedDate = #" & Me.txtDestroyDate & "#" _
& ", DestroyedBy = '" & Me.txtDestroyedBy & "'" _
& ", Witness = '" & Me.txtDestroyWitness & "'" _
& ", ScanExists = 0" _
& " WHERE Project = '" & !PROJECTID & "' AND Path = '" & !pathname & "'" _
& ";", dbFailOnError
End If
.MoveNext 'Advance to the next record
Loop
End With
On Error GoTo 0 'Resume normal error handling
rstErrorTable.Close
Set rstFormRecords = Nothing
Set rstErrorTable = Nothing
Set db = Nothing
SysCmd acSysCmdSetStatus, " "
... The value for !PathName is
X:\DocumentRetention\ProjectScans\aTemp\toby.txt
and it is a string (Text data type in the table). I do have access to the network drive and can add/edit/delete files there.
What am I doing wrong? Is there another way to delete a file instead of KILL()? :help
This is the command I'm using:
Kill !pathname 'Delete the electronic file! which is found here:
...
'Now delete the files!
SysCmd acSysCmdSetStatus, "Deleting electronic files..."
On Error GoTo Err_Execute 'Use our error handling
bError = False 'Set default
Set db = CurrentDb 'Get our [current] database
Set rstErrorTable = db.OpenRecordset("tblDestroy_Electronic_Err") 'Get the table for capturing errors
Set rstFormRecords = Me.FilesToDestroy.Form.Recordset 'Get the records from the subform
With rstFormRecords
.MoveFirst 'Make sure we start at the beginning
Stop 'Testing
Do While Not .EOF 'Loop thru all the records until we hit the end
bErrorFlag = False 'This flag is set to TRUE in the error handler (indicates an error occurred)
Kill !pathname 'Delete the electronic file!
'Update DestroyedDate, DestroyedBy, Witness, and ScanExists fields in tblMasterScans but make no updates to tbl_Project_Locations.
If Not bErrorFlag Then
db.Execute "UPDATE tblMasterScans SET DestroyedDate = #" & Me.txtDestroyDate & "#" _
& ", DestroyedBy = '" & Me.txtDestroyedBy & "'" _
& ", Witness = '" & Me.txtDestroyWitness & "'" _
& ", ScanExists = 0" _
& " WHERE Project = '" & !PROJECTID & "' AND Path = '" & !pathname & "'" _
& ";", dbFailOnError
End If
.MoveNext 'Advance to the next record
Loop
End With
On Error GoTo 0 'Resume normal error handling
rstErrorTable.Close
Set rstFormRecords = Nothing
Set rstErrorTable = Nothing
Set db = Nothing
SysCmd acSysCmdSetStatus, " "
... The value for !PathName is
X:\DocumentRetention\ProjectScans\aTemp\toby.txt
and it is a string (Text data type in the table). I do have access to the network drive and can add/edit/delete files there.
What am I doing wrong? Is there another way to delete a file instead of KILL()? :help