DS said:
Thanks Douglas,
I have a series of Backup files that I run for 7 days, after the 7th day
it deletes anything older than 7 days.
Well so far I no longer get an error if the file doesn't exist. Byt it's
not deleteing the old file. Could it be that the formats are different?
It should be in this format mmddyy.
It likely is. You're explicitly telling it to look for files that have the
date in yyyymmdd format. If they're in mmddyy format, then it's no surprise
that it's not finding them!
Your code isn't deleting anything older than 7 days. If you want it to
delete a single file that's exactly 8 days old, you'd need:
Dim strFile As String
strFile = "C:\Proserv\BU\" & Format(Date - 8, "mmddyy") & ".MDB"
If Len(Dir(strFile)) > 0 Then
Kill strFile
End If
FileCopy "C:\PROSERV\DB\Restore.mdb", _
"C:\PROSERV\BU\" & Format(Forms!frmFXEOD!TxtBizDate, "mmddyy") & ".mdb"
If you wanted to check for files that were, say, 8 to 14 days old, you'd
need a loop:
Din intLoop As Integer
Dim strFile As String
For intLoop = 8 To 14
strFile = "C:\Proserv\BU\" & Format(Date - intLoop, "mmddyy") & ".MDB"
If Len(Dir(strFile)) > 0 Then
Kill strFile
End If
Next intLoop
FileCopy "C:\PROSERV\DB\Restore.mdb", _
"C:\PROSERV\BU\" & Format(Forms!frmFXEOD!TxtBizDate, "mmddyy") & ".mdb"
Note that I've moved the FileCopy statement outside of the If loop: the way
you had it, you'd only be copying the file if an 8 day old file existed.