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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

auto backup to a different folder

Status
Not open for further replies.

kdoran

Technical User
Mar 23, 2003
88
US
What line do I need to change or add to backup to a different folder?

Using Access 2000

'*****begin code******

Private Sub Form_Timer()
'==================================================================
'The Timer event runs this code every minute. It compares your
'system time with the StartTime variable. When they match, it
'begins compacting all databases in the DBNames table.
'==================================================================
Dim StartTime As String
' Set this variable for the time you want compacting to begin.

StartTime = "9:00 AM"


' If StartTime is now, open the DBNames table and start compacting

If Format(Now(), "medium time") = Format(StartTime, _
"medium time") Then

' Dim RS As DAO.Recordset, DB As DAO.Database
Dim NewDBName As String, DBName As String
Set DB = CurrentDb()
Set RS = DB.OpenRecordset("DBNames")
On Error Resume Next
RS.MoveFirst
Do Until RS.EOF
DBName = RS("DBFolder") & "\" & RS("DBName")
' Create a new name for the compacted database.
' This example uses the old name plus the current date.
NewDBName = Left(DBName, Len(DBName) - 4)
NewDBName = NewDBName & " " & Format(Date, "MMDDYY") & ".mdb"
DBEngine.CompactDatabase DBName, NewDBName
RS.MoveNext
Loop
' Close the form, and then close Microsoft Access
DoCmd.Close acForm, "CompactDB", acSaveYes
RS.Close
DoCmd.Quit acSaveYes

End If

End Sub
'*****end code*******


Thanks,

Kelly
 
I'm interested in why u back up and compact databases every minute.
I think that databases who are in use not compact or backup with this code,
But answering your question:
RS("DBNAME") SET to "C:" or somewhat...

Gerard
Ps:If u need more help u can ask. I have some code to backup a database which is in use. It's only for 1 database, but u can set it trough all databases.
 
correction: haven't seen u compare with 9.00 AM, but also all databases must be closed in this way..
 
gerard1979,

I am taking you up on your offer on help. I am new to vba coding. I would like to see your code for backup a database. I will need to set it to do all db's.

Thanks,

Kelly

Oh yeah, for the above code I posted here is what was missing..

The above code came from thread702-438670 (Auto Backup in Access). Here was the instructions from it....

.....You can backup more than one database with this code. You need a table setup to define the database(s) you want to backup.

TableName: DBNames
Fields: DBID, DBFolder, DBName

DBID is the autonumber.

DBFolder is the location of where the database(s) are located. Formated like (mine are on a network drive): \\gaf5142tnscs001\shared\ESCMAD

DBName is the name of your database file(s) you want to backup. Format like: ESD_be.mdb

This code goes in the OnTimer event. Set the time interval to 60000 (1 minute). The code will check the time every minute to see if it matches the time that is programmed to begin your backup.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top