Public Const BackupPath As String = "D:\Documents\Access\James Hardie\Version 2.0\Backups"
Public Sub BackupData()
Dim strFile As String
If Len(Dir(BackupPath, vbDirectory)) = 0 Then
Call MkDir(BackupPath)
End If
Call DeleteOldBackups
If Len(Dir(BackupPath & "\" & CStr(Format(Date, "mmddyyyy")) & ".mdb")) = 0 Then
FileCopy Application.CurrentProject.Path & "\" _
& Left(Application.CurrentProject.Name, InStr(1, Application.CurrentProject.Name, ".") - 1) _
& "_be.mdb", BackupPath & "\" & CStr(Format(Date, "mmddyyyy")) & ".mdb"
End If
End Sub
Private Sub DeleteOldBackups()
Dim fso As New FileSystemObject
Dim fol As Folder
Dim fil As File
Dim strName As String
Set fol = fso.GetFolder(BackupPath)
For Each fil In fol.Files
strName = Left(fil.Name, 2) & "/" & Mid(fil.Name, 3, 2) & "/" & Mid(fil.Name, 5, 4)
If CDate(strName) <= DateAdd("d", -30, Date) Then fil.Delete
Next
End Sub