Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Mar 2006
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    289
    Thanks
    0
    Thanked 1 Time in 1 Post

    Delete files (2003 SP2)

    What is wrong with this function...except the fact that it does not work???

    Public Function DeleteFiles()
    Dim RS As DAO.Recordset, DB As DAO.Database
    Dim strFileName As String
    On Error GoTo ErrHandler
    Set DB = CurrentDb
    Set RS = DB.OpenRecordset("tblFileNames")
    RS.MoveFirst
    Do Until RS.EOF
    strFileName = RS("Folder") & "" & RS("FileName")
    Shell "cmd /c del strFileName"
    RS.MoveNext
    Loop
    ExitHandler:
    On Error Resume Next
    RS.Close
    Set RS = Nothing
    Set DB = Nothing
    Exit Function
    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Function
    Thanks
    chuck

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Delete files (2003 SP2)

    Instead of

    Shell "cmd /c del strFileName"

    try

    Kill strFileName

  3. #3
    3 Star Lounger
    Join Date
    Mar 2006
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    289
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Delete files (2003 SP2)

    I would not have thought of Kill. I had seen that in past reading but these things just do not come to me. Of course it did the trick.

    By the way, I appreciated that little blurb you wrote about yourself the other day, and the picture.

    507 days to retirement.
    Thanks
    chuck

  4. #4
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Delete files (2003 SP2)

    Get rid of the command

    RS.MoveFirst

    as the SET RS = .... command positions the recordset at the beginning anyway.

Posting Permissions

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