Sunday, June 13, 2004

Some time ago I added a feature to my data entry application (Written in Microsoft Access 2000) that backs up the main table to an excel file when you close the data entry form.

Well, at the time I couldn't figure out how to delete files after they were so old, like 30 days or so. This was a safety feature because the whole access files are sometimes deleted when a file is sent ftp or something overwriting the original.

Anyway, I left the delete portion for later and forgot. So my users have been having excel files pile up on their hard drive and I didn't realize it until know. Some users would have to have upwards of 1 gig of files from this feature.

I realized this 2 days ago and finally figured out how to delete files in that backup directory that are older than 30 days. Here is the code:

On Error GoTo Err_Command1_Click

Dim ss As String
Dim strPath As String

strPath = "c:\cm\backup\"
ss = Dir(strPath & "*.*")

If ss <> "" Then
While ss <> ""
If DateDiff("d", FileDateTime(strPath & ss), Now()) > 30 Then
Kill (strPath & ss)
End If
ss = Dir()
Wend

End If

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click

One day I hope to grow up and not be such a careless programmer. I hard a hard time finding this code, mainly because I couldn't figure out how to search for it. Works like a charm though. Tested it myself and also on an employees computer. We will see if there are problems next week.