Hi,
I'm trying to run a macro that runs an archive command once per year. But, I need to make sure that the archive actually happens after a certain date even if the program isn't opened on that specific date to run the macro. For example, I need to archive all my records on March 31 every year. But if March 31 happens on a Saturday, no one is going to open the program, so the macro won't run. And the next time the program will be opened is the following Monday. Therefore, I've come up with the following code with the issue of somehow using an "exists()" function in access:
Code:
if exists(archivecount)=false thenarchivecount = 0
end
temp2 = DateDiff(yyyy,#31/03/2014#,Now())
if archivecount < temp2 then
archive()
archivecount = temp2
end
The reason for the first if statement is because I need to initialize the variable 'archivecount' if it hasn't already been set. I don't want to reinitialize the variable every time the code is run because I want to run the code every time the program opens and because my infinite archivecount is what determines if the actual archive() command should be run.
For example, in 2016, the difference between 2016 and 2014 is obviously 2 years and if archivecount is less than 2, then that means the archive() function should be run....