Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic backups

Status
Not open for further replies.

rafal444

Programmer
Aug 11, 2006
74
US
How do I setup automatic backups in Access? I setup OnTimer event on the form. The problem is that the form needs to have focus...

The code, it copies the current db into new file...

Any idea how to get this working when other forms are open? Maybe other solution?
 
How is you database set up, that is, is it split (BE/FE)?
Have you considered backing-up on exit of the database or using the Windows scheduler?
 
Have you considered backing-up on exit of the database or using the Windows scheduler?
 
Do you have more details regarding the scheduler? What exactly I need to setup?

Right now it just backups from inside of MS Access, OnTimer method of the form...
 
How do I create a copy of mdb every one hour? Will it work when db is open. I also do not want to overwrite the old files. Just keep daily backups for 7 days, and keep all weekly backup for a year...
 
Here's something I setup for an old database I was working on. You would need to look at the paths and stuff and change them to what you need. I also don't have any error checking or the like in this. I put this bit of code in module, then just executed the BackupData() in the startup form for the application.

Basically, when the database is opened, it checks to see if a backup for the backend exists. If it doesn't, it creates it. If it does, it just moves on. The first person to open the database each day was the lucky one to "create" the backup...The "backup" process also deleted anything older than 30 days, as this was the client requirements.

If this works for you...kewl. If not, it should get you something to get started with in finding a solution.

Code:
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

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
mstrmage1768, I think it is the "How do I create a copy of mdb every one hour?" that is the puzzle, or do you not read rafal444's posts that way?
 
It seems to me that there is no need to launch Access at all, it is already open. All that is needed is a batch file or a little script to copy the MDB. This can be run every hour using scheduler.
 
Yes, you are right Remou. I'm reading with my 'derriere' as well.



Pampers [afro]
Keeping it simple can be complicated
 
I tried it with the build in WindowsXp backup facility... that looks like it will work. Like:

Start, Programs, Accessories, System Tools, BackUp (Wizard-mode), Backup Files and Setting, Let me choose what to back up, Select your Access File, Next, Next..., Advanced, (When) Later, Set Schedule, Advanced, Repeat Task, Daily, Every 1 hour, untill 23:59, startTime: 00:01; set TaskName, set TaskPassword, Finish

Pampers [afro]
Keeping it simple can be complicated
 
Thanks, I have the backup procedure, it is the scheduler I need to get working with the code...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top