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

Timer Interval Property

Status
Not open for further replies.

llafretaw

MIS
Oct 2, 2001
64
0
0
GB
Hi, I'm having a bit of hassle with regard to using the timer interval property.I want my code to go off and check the systime every hour, but can only use the timer interval property to execute my code after a maximum time of 1 min. This however is too frequent and it also uses up to much cpu time, is there any way for example of executing this do loop while the form is open without using the timer function? any help would be appreciated...
 
What are you setting the timer interval to? Please note that it is in milliseconds, so for one hour, you would need to put in: 3,600,000 (60 secs * 60 minutes * 1000 milliseconds). My app (Access2k) will allow a timer interval that is set that high. Give us more info so we can better diagnose your situation.

I wouldn't recommend a loop, as that will be running indefinitely - and will consume much more resources than a Timer Event.

Let me know how this works, and again, please give more info....

Regards,

Kevin
 
Well I read that the max amount of milliseconds that u could set the timer interval was 65000 + sec on Access VBA 1997, i.e. just over a min. Have since tried setting it to run every hr at hh:00:00, and so will have to wait and see whether that works.I have however set up a do loop to execute every hr, till it reaches the desired time to prompt one with the choice to close down the app or keep working away...here is what the code roughly consists of, as i can't see any other way of avoiding the use of the loop?
Dim GetTime As Date
Dim TimeNow As Date
Dim CheckTime As Boolean

CheckTime = False

Do
Do While TimeNow <> (&quot;18:00:00&quot;)
GetTime = Now()
TimeNow = Format(CStr(GetTime), &quot;hh:00:00&quot;)
If TimeNow = (&quot;18:00:00&quot;) Then
If MsgBox(&quot;Do you wish to exit the application? &quot; vbYesNo) = vbYes Then
DoCmd.Quit
Exit Sub
End If
CheckTime = True
Exit Do
End If
Loop
Loop Until CheckTime = True
Exit Sub

or am i totally going dowm the wrong track?
 
I haven't verifed your statement regarding the max value of an A297 Timer Interval... but I believe you. I found the following code on Microsoft's web site showing how to compact a database everyday at midnight. By the comments in their own code, they acknowledge that this code will run once every minute to check the system time. That means that it needs to run 1,440 times per day just so that it can catch the one instance when it is needed. That's not very efficient... but it is more efficient that your code.

Your code will continue to run without stopping until the time is 1800. If that loop starts when a user logs in at 0800, it will not stop looping until 1800... that's a lot of wasted resources.

I recommend that you run your code once an hour and check to see if the current time is greater than or equal to 1800. If the function fails (ie, it's earlier than 1800), then exit the loop. (Your loop continues until the function returns true). Your code will then run again in an hour to check the function.

Here is Microsoft's Code... if you need help adapting it to your need, please let me know, and I'll work with you.

Have a great day!

Rock ON!

Kevin

Private Sub Form_Timer()
'==================================================================
'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 = &quot;12:00 AM&quot;
' If StartTime is now, open the DBNames table and start compacting
If Format(Now(), &quot;medium time&quot;) = Format(StartTime, _
&quot;medium time&quot;) Then
Dim RS As Recordset, DB As DATABASE
Dim NewDBName As String, DBName As String
Set DB = CurrentDb()
Set RS = DB.OpenRecordset(&quot;DBNames&quot;)
On Error Resume Next
RS.MoveFirst
Do Until RS.EOF
DBName = RS(&quot;DBFolder&quot;) & &quot;\&quot; & RS(&quot;DBName&quot;)
' 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 & &quot; &quot; & Format(Date, &quot;MMDDYY&quot;) & &quot;.mdb&quot;
DBEngine.CompactDatabase DBName, NewDBName
RS.MoveNext
Loop
' Close the form, and then close Microsoft Access
DoCmd.Close acForm, &quot;CompactDB&quot;, acSaveYes
RS.Close
DoCmd.Quit acSaveYes
End If
End Sub
 
cheers for the help mate, I'll give it a shot and see what happens
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top