Another run-once question

AUGuy

Newly Registered Idiot
Local time
Today, 05:02
Joined
Jul 20, 2010
Messages
135
Hey guys! First time poster, many time reader.

I've got a function (Daily_Archive) that I need to run only once a day. I've decided the base fit for me is to have a table (Test_Date) contain the date the function was last run.

What I need it to do, to avoid duplicating data within the Db or causing other irritating problems, is to check the current date against the date in Test_Date, and perform the rest of the function if they do not equal. Presumably the date in Test_Date would always be the day before.

Here's the code i've pieced together thus far (but does not include the comparison logic).

Code:
Option Compare Database
Function Daily_Backup()
Dim CurrentDate As String
Dim dbDatabase As Object
Dim rstTest_Date As Object
CurrentDate = Date
CurrentDate = Format(CurrentDate, "MMDDYY")
Set dbDatabase = CurrentDb
Set rstTest_Date = dbDatabase.OpenRecordset("Test_Date")
rstTest_Date.Edit
rstTest_Date("Test_Date").Value = CurrentDate
rstTest_Date.Update
End Function

I'm by no means a programmer, i've only put this much together by reading help files. I'm sure i've committed several coding atrocities, so be gentle!

thanks in advance.

Guy
 
Try this


Code:
If DMax("TestDate","YourTable") < Date() Then
   'Need to run the backup
Else
   'Aready Done
End If


Then When you have done the back up

Code:
DoCmd.SetWarnings False
DoCmd.RunSQL "Update Table Set DateField = Date()"
DoCmd.SetWarings True

Table and field names are for brevity only. Use you own names
 
Thanks! I'll give this a shot and get back to you!

Edit: Worked like a charm, thanks a bunch!!
 
Last edited:

Users who are viewing this thread

Back
Top Bottom