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

Help With Code

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
US
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
 
Name Statement Example
This example uses the Name statement to rename a file. For purposes of this example, assume that the directories or folders that are specified already exist. On the Macintosh, “HD:” is the default drive name and portions of the pathname are separated by colons instead of backslashes.

Dim OldName, NewName
OldName = "OLDFILE": NewName = "NEWFILE" ' Define file names.
Name OldName As NewName ' Rename file.

OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"
Name OldName As NewName ' Move and rename file.

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
What part of the current code would i take out?

I tryed a couple of different ways but cant seem to make it work

Thanks DVannoy
A+,Network+,CNA
dvannoy@onyxes.com
 
? Take-Out? Chinese food?

Just put the "whole thing" after the rs.movenext

You need to (re)Name both

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Im sorry man i not getting this..

The path to my database id L:\Facility\Azusa.mdb

when i put that in your code it still adds the current date after the file name..

If i remove then line of code that tells it to create the file with the date after it, it wont work...i get no errors but it just wont work..

DVannoy
A+,Network+,CNA
dvannoy@onyxes.com
 
O.K.

Let your original code do its thing.

You end up with two dbs. Azusa and AzusaMMDDYY the former is the "original" (where MMDDYY refers to the currentdate) and the latter is the compacted one w/ todays date, Right?

Now, just do the two renames "Name" (Method already posted).

I'll Assume that you are keeping the old one for some period of time, so Azusa is NAMED[/color AzusaMMDDYY except this date string refers to YESTERDAY, and AzusaMMDDYY (where MMDDYY refers to the currentdate) is NAMED Azusa

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top