I got this code from the microsoft web site. it will compact any database at the time you set. what Im trying to do with this is once the database gets compacted it creates a new database ..same name but adds the current date after the name..i want this code to compact my database but somehow use the same name. even if there is a way to add the word "old" to the database that got compacted and take off the date from the other database..I want to run this code after my server gets backed up...so my users dont have to wait for me to get in..if i can rename the compacted database to the original name that would solve a big this problem....
Heres the code
'==================================================================
'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 = "12: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 Recordset, DB As 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
DVannoy
A+,Network+,CNA
dvannoy@onyxes.com
Heres the code
'==================================================================
'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 = "12:00 AM"
' If StartTime is now, open the DBNames table and start compacting
If Format(Now(), "medium time"
"medium time"
Dim RS As Recordset, DB As 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"
' 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"
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
DVannoy
A+,Network+,CNA
dvannoy@onyxes.com