Consulting

Results 1 to 3 of 3

Thread: Solved: How to delete a file when KILL doesn't work?

  1. #1

    Angry Solved: How to delete a file when KILL doesn't work?

    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!

    This is the command I'm using:
    [vba]Kill !pathname 'Delete the electronic file![/vba] which is found here:
    [vba]...
    '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, " "
    ...[/vba] 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()?
    Toby
    Portland, Oregon

  2. #2
    Searching got me these two URLs to try another method:
    http://visualbasic.ittoolbox.com/gro...03-vba-2539018 and http://stackoverflow.com/questions/6...-a-file-in-vba
    so I tried this in place of the KILL command and it, too, produces the same error:
    [vba]
    Dim fso As New Scripting.FileSystemObject
    ...
    fso.DeleteFile (!Pathname), True 'True or False doesn't seem to matter
    ...
    [/vba]

    What could be causing Access to not "see" the file?
    Toby
    Portland, Oregon

  3. #3

    Thumbs up


    Nevermind, stupid user error by me

    The filepath in the test record used "...aTemp..." but I named the test directory "...aTest...". Once I changed the directory name all worked as expected. Oh boy.

    What got me here was trying to fso.MoveFile the file using the file system object. When I got the error that the Path doesn't exist I studied the two paths character by character and that's when I saw the discrepancy
    Toby
    Portland, Oregon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •