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

Help With Creating A Timer 2

Status
Not open for further replies.

Jayz

ISP
Feb 17, 2002
59
I need to create a timer that counts down from 5 minutes in the format mm:ss on a form when it opens.
I'm unsure how to do this.

Someone please help

Rgrds
Jay
 
Hello. I put together a little something that was able to do what you asked. Of course in Access there is always more than one way to skin a cat. Here is mine.

1. Add two text boxes to a form. Call them txtMins and txtSecs.
2. Set the default value of txtMins to 5 and txtSecs to 0.
2. Set the Form's Timer Interval to 1000 (Which is 1 second).
3. Add the following code to the Option Explicit, Form Load and Form Timer events.



Option Compare Database
Option Explicit
'Here we Declare the Total Seconds variable
Dim TotSecs As Integer

Private Sub Form_Load()
'This determines the number of seconds to count
TotSecs = 300
End Sub

Private Sub Form_Timer()
'This lines counts away the seconds
TotSecs = TotSecs - 1

'These two lines convert total seconds
'into Minutes and Seconds
txtMins = Int(TotSecs / 60)
txtSecs = Int((((TotSecs / 60) - txtMins) * 60) + 0.5)

'The following stops the timer when it gets to zero
If txtMins = 0 And txtSecs = 0 Then
Me.TimerInterval = 0
End If

End Sub


Hope this helps.



prodevmg@yahoo.com
ProDev, MS Access Applications B-)
May God bless you in the year 2002.
 
Thanks a Million Lonnie,
Just what the Doctor ordered.

Just on the side, and I'm not too worried if there is no solution.
Is there a way to format the seconds control so that it displays it in the form 00?.
At the moment when it gets to single figures it doesn't display the 0(zero) in front. eg it displays 9 instead of 09.

Regardless of the outcome, I'm happy with what has been produced.

Once again
Thanks.

Rgrds,
Jay
 
Format(TotSecs/86400,"n:ss") will do the job....

If you're wondering how.....

86400 is the number of seconds in a day.....Access dates are based on days.....so TotSecs divided by 86400 give the fraction of a day.....

Now you need to display it in the right foramt....so use the format function with the mask "n:ss"......n denotes minutes (m is already take by month)........

And you only need one text box too....

Craig
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top