Form Tmer not running everytime (1 Viewer)

RickK

Registered User.
Local time
Today, 12:45
Joined
Oct 27, 2013
Messages
35
I have an On Timer event on my main form set to run every day at 6:00 AM. It runs a macro that generates a report and saves it in PDF in a folder. It works most of the time but for some reason when the customer comes in at 7AM and checks the folder the report is missing. This fails to run maybe twice a week. The Access DB runs 24 /7 and is used on all shifts. I am wondering if the monitor is going into screen saver mode and causing issue. I have only been able to reproduce it on my PC once by leaving the DB running over night and then I checked it in the morning and it was missing. If I try to duplicate it by changing the time that it should run and then letting screen saver start, it will not fail.
Here is my code in the Form timer:
Code:
Private Sub Form_Timer()
 If TimeValue(Now()) >= #6:00:00 AM# Then
        Dim stDocName As String
    stDocName = "DailyDownTimeChart"
    DoCmd.RunMacro stDocName
        Me.TimerInterval = 0
    End If
End Sub
The time interval is set to 35000, so that it will catch the 6:00 AM. Could the last set of 00's be causing the issue? Could this be removed?

Is there a log that I can turn on that will show if it tried to run and why it failed?
I just read a thread that said Access was not designed to run 24/7 without being restarted. Is this true and could it be my problem?
Thanks for any ideas
Rick
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:45
Joined
Feb 19, 2013
Messages
16,607
how close to 6am do you need to be? at the moment it is running every 35 seconds which seems a bit extreme to run a single event overnight - why not once an hour?

So number is quite small - the max is 2,147,483,647 which is the equivalent of 24 hours.

There is no reason why access cannot run all the time, but any application will need restarting occasionally, if only to absorb updates or because of other events such as machine restarts.

Suggest you would be better off setting up a windows task to start at 6am, the task being to open access and run your macro. The access file it opens does not have to be your users version, it can be one which contains sufficient to achieve the task required.
 

RickK

Registered User.
Local time
Today, 12:45
Joined
Oct 27, 2013
Messages
35
It doesn't have to be 6 AM exactly. Just anytime after midnight so it will be available by 7 AM the next morning.

Suggest you would be better off setting up a windows task to start at 6am, the task being to open access and run your macro. The access file it opens does not have to be your users version, it can be one which contains sufficient to achieve the task required.

How would I do this? How would I have Access open and run a macro in the DB that is already open?
 

isladogs

MVP / VIP
Local time
Today, 20:45
Joined
Jan 14, 2017
Messages
18,213
In your database create code to run your report, create the PDF then exit the database when the Access command line argument = "CreatePDF"

OR ... as suggested by CJ_London use a 'special' version of your db with an autoexec macro to do the above items & exit

Create a scheduled task to start Access & run your database with the above command line argument (if using that approach) at the chosen time e.g. 06:00
NOTE you have to do both of these things in the scheduled task

Run Program : Enter path to MSAccess here
e.g. C:\Program Files\Microsoft Office\Office14\MSACCESS.EXE

Arguments: Enter path to your database ....followed by cmd /CreatePDF if using the command line argument idea
e.g. C:\Programs\MendipDataSystems\SDALink\SDALink.accdb /cmd "CreatePDF"

Attached is an example of a scheduled task to act as a guide if you want to use it.
Its an XML file which I've zipped so I could post it here
If you want to look at it, unzip then open Task Scheduler & import the XML file
Modify times, file names & command line argument as needed.
Run it to test it works OK then leave it to run automatically at 06:00
 

Attachments

  • Run SDA Link Attendance Marks.zip
    1.5 KB · Views: 52
Last edited:

RickK

Registered User.
Local time
Today, 12:45
Joined
Oct 27, 2013
Messages
35
Thanks for the suggestions but this does not answer my question of why the way that I have it set up fails to run sometimes.
I have this installed in several locations and this is the way I was told to set it up from people on this forum. I cant go back and change it at this point. I was really looking for reasons whay it runs most of the time but fails to run once or twice a week.

I have heard of guys claiming they "checked the logs" . What logs are they talking about. How can I set the logs to record why it is failing? Or does anyone have input as to why this method would fail?

Thanks
Rick
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:45
Joined
Feb 19, 2013
Messages
16,607
why the way that I have it set up fails to run sometimes
no idea - perhaps the macro that produces the pdf fails, perhaps the directory it is writing it to is not available at that point in time. perhaps someone touched the machine and reset the timer interval to 0. perhaps IT reboot the machine overnight to consume updates, perhaps something else.

You mention the screen saver - suggest try some more experiments - if every time the screensaver is activated, you don't get the file, and every time you disable the screen saver you do, then that is your answer.

Don't know what logs are being referred to - perhaps your it dept maintains some sort of read/write event log, or perhaps these comments come from people who are creating their own logs.

You can create your own log -simply a debug.print the current time to see in the immediate window every time the timer event is checked, or write to a temporary table. Set it running, turn the screensaver on, leave for a few minutes, turn it off and check what you have. If the log has continues to update, it is not the screen saver (or at least not as a result of this code)

As mentioned before, a cycle time of 35 seconds seems excessive. Suggest change the time to 1am and the timer interval to 3600000 (1 hr).
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:45
Joined
Feb 28, 2001
Messages
27,172
The question is not whether the code runs, but when it runs, does it reset the timer each time? I don't recall that a timer event automatically reloads a timer interval and the code you showed us (so far) doesn't show us the timer reset either.

You showed us this sequence:

Code:
 If TimeValue(Now()) >= #6:00:00 AM# Then
        Dim stDocName As String
        stDocName = "DailyDownTimeChart"
        DoCmd.RunMacro stDocName
        [COLOR="Blue"]Me.TimerInterval = 0[/COLOR]
    End If

The line in blue would stop the timer so that after running your macro once, you would no long be ticking down your timer. In essence, with this code I would NEVER expect to see the report run two days in a row without intervention. It would run once and stop.

If there is nothing else going on in the timer, I would pick an interval that comes out as an even divisor of the time of day, like 60000 (sixty thousand) for the timer. Once per minute will be fine for this purpose. But then again, there is always the sneaky method.

If you REALLY want this as a feature of a continuously running Access, just remember that the x=Timer() function gives you the milliseconds since midnight as a LONG. The time of day you selected is just 6 * 60 * 60 * 1000 milliseconds, or 21,600,000. If there is nothing else for that form's timer to do at lesser intervals, just compute the time of day at which you want that function to run again based on the current time. There will be only two possible cases.

Code:
Private Sub Form_Timer()

Const RunMSec as LONG = 21600000
Const DayMSec as LONG = 86400000
Dim Msec as LONG

MSec = Timer()

IF MSec > RunMSec Then
      Me.Timer = (DayMSec - MSec) + RunMSec
ELSE
      Me.Timer = RunMSec - MSec
END IF

' {whatever you wanted to run at 0600, run it here}

End Sub

What this does is computes the milliseconds until the next time that the timer event should run. If you really didn't want 6:00:00, then compute the seconds since midnight of the time you want and tack on three more zeros.

The timer for this would only run once per day. Then, to "prime the pump", put the IF/THEN/ELSE/END IF sequence above into the Form_Open or Form_Load routine but don't trigger your report operation for that case. If your timer code is multi-purpose, then this will not work correctly because the other scheduling would require a more frequent awakening of the timer code.
 

missinglinq

AWF VIP
Local time
Today, 15:45
Joined
Jun 20, 2003
Messages
6,423
A bug that resulted in the 'disappearing of calculated fields' appeared with release of ACC 2010. This problem was finally identified as being caused by the errant PC being left running for extended periods of time, and might be connected with the problem, here, as Reports frequently include calculated Fields!

The immediate fix is to reboot the PC; the definitive fix is a hotfix:

For 2010

http://support.microsoft.com/en-us/kb/2899528

Take time to read the article before clicking on 'Hotfix Download available' button, especially the part about Prerequisites (To install this hotfix package, you must have Office 2010 Service Pack 2 (SP2) installed)

For 2013

http://support.microsoft.com/en-us/kb/2956176

As to what you're doing, I, too, would recommend using the Task Scheduler, rather than using the Timer event of a Form; the later is resource heavy, and can, in and of itself, cause problems, especially if you have multiple Forms open simultaneously.

Linq ;0)>
 

Users who are viewing this thread

Top Bottom