Results 1 to 4 of 4
  1. #1
    gemadan96 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    110

    Deleting Files based on criteria

    I have a module used to backup the backend database. It does exactly that. I've added code to insert a record in to a table (BackupLog) that includes the path and file name of the backup. That works. I've also added code to determine if any of my backups have expired and if they have mark them for deletion. That works.

    Now I'm trying to add code that will delete the expired backups. The code I have so far is below.

    'Delete Expired Backups
    Dim strRS As String
    strRS = "Select * FROM BackupLog WHERE Delete = True"
    Dim rs As Recordset
    Dim BUFileDelete As String
    Set rs = CurrentDb.OpenRecordset(strRS)
    If rs.RecordCount > 0 Then
    rs.MoveFirst
    Do Until rs.EOF
    BUFileDelete = rs![BackupFile]


    Kill BUFileDelete
    Loop
    Else
    MsgBox "No expired backups"
    End If
    Set rs = Nothing

    When I run it I get a message 53: File not found. The expired files don't get deleted. Everything else works.

    Any suggestions are appreciated.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    I tested the Kill method using a variable and it works. Have you step debugged? Does the variable get set with expected values?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    gemadan96 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    110
    Did the step debug. It seems to be a problem with the loop. In testing there are two files to delete. It deletes the first one then goes back to the start of the loop. What it's not doing is moving to the next file. I'm getting the file not found error because the file has been deleted.

    Found that I left the following out right before the loop statement: rs.MoveNext. Put that in and it works.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,943
    And I see that now. Glad you found it and is working.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 11-20-2012, 03:31 AM
  2. Export Access into multiple excel files based on field value
    By turntabl1st in forum Import/Export Data
    Replies: 7
    Last Post: 11-08-2012, 12:43 PM
  3. Replies: 5
    Last Post: 07-06-2012, 03:22 PM
  4. Copying and Rename of Files based on fields
    By desk4tbc in forum Programming
    Replies: 2
    Last Post: 06-28-2011, 11:00 AM
  5. Replies: 11
    Last Post: 12-14-2010, 01:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums