I currently have a database with a front end of just code and four back-ends with just data. I have several back ends to manage the size of the databases, as well as to group like data in one place, which makes it easier to manage (personal preference).
Whenever my FE opens, it checks to see the last time the BEs were backed up and if it has been more than six hours, it will make copies of the BEs and save them to a Backup folder. The DB also adds a time stamp to each copy, so that I know, just by looking at the file name, when the file was backed up. The file itself, may be older than 30 days, because not all of my BEs are accessed every day. Having it back up EVERY time the DB was opened would definitely cause things to quickly get out of hand.
However, as you can guess, backing up several BEs several times a day (ranging from 4-50 MB each) quickly causes a strain on storage space. Right now, I occasionally go into my BACKUP folder, find the older files (>30 days) and just delete them.
Here is what I want to do:
When the FE opens, have the DB check the list of files, find the date stamp, decode it, and if the file was backed up more than 30 days ago, delete it. This way, I will only have no more than 30 days' worth of BEs.
My challenge is, how do I tell the DB to go to a particular directory and go through a list of files? Then, is it possible for VBA to delete files from a directory?
Any assistance would be appreciated.
For reference, here is the code I use for my backup:
Whenever my FE opens, it checks to see the last time the BEs were backed up and if it has been more than six hours, it will make copies of the BEs and save them to a Backup folder. The DB also adds a time stamp to each copy, so that I know, just by looking at the file name, when the file was backed up. The file itself, may be older than 30 days, because not all of my BEs are accessed every day. Having it back up EVERY time the DB was opened would definitely cause things to quickly get out of hand.
However, as you can guess, backing up several BEs several times a day (ranging from 4-50 MB each) quickly causes a strain on storage space. Right now, I occasionally go into my BACKUP folder, find the older files (>30 days) and just delete them.
Here is what I want to do:
When the FE opens, have the DB check the list of files, find the date stamp, decode it, and if the file was backed up more than 30 days ago, delete it. This way, I will only have no more than 30 days' worth of BEs.
My challenge is, how do I tell the DB to go to a particular directory and go through a list of files? Then, is it possible for VBA to delete files from a directory?
Any assistance would be appreciated.
For reference, here is the code I use for my backup:
Code:
'Database Path constants in another module
Public Const strDBASEPATH As String = "\\ServerName\DATABASE\"
Public Const strBACKUPPATH As String = "\\ServerName\DATABASE\BACKUP\"
'Code within my start up form
If Me.txtLastBackup < Now - 0.25 Then
Dim FSO
Dim strDate As String
strDate = Format(Date, "yyyy-mm-dd") & "-" & Format(Time, "hh-mm")
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile strDBASEPATH & "DATA\DATA-BE1.accdb", strBACKUPPATH & "DATA-BE1 BACKUP - " & strDate & ".accdb"
FSO.CopyFile strDBASEPATH & "DATA\DATA-BE2.accdb", strBACKUPPATH & "DATA-BE2 BACKUP - " & strDate & ".accdb"
FSO.CopyFile strDBASEPATH & "DATA\DATA-BE3.accdb", strBACKUPPATH & "DATA-BE3 BACKUP - " & strDate & ".accdb"
FSO.CopyFile strDBASEPATH & "DATA\DATA-BE4.accdb", strBACKUPPATH & "DATA-BE4 BACKUP - " & strDate & ".accdb"
Me.txtLastBackup = Now
End If
Comment