Countdown timer with time format(00:00:00)

libin04

New member
Local time
Today, 19:14
Joined
Aug 10, 2022
Messages
18
I am creating Access db which needs auto close the db using timer count down. for example, if I give 5 min then it should start count down displaying this time format 00:04:59

I have found several pieces of tips checking the web, but did not manage to fit the pieces to one working piece.

Below is working perfect. but in output i can see only min and sec 0:00. How to add code for hours as well (format 00:00:00)? I tried to add hours but it is not working


Code:
Private Sub Form_Load()

Me.TimerInterval = 1000

Form_Timer

End Sub


Private Sub Form_Timer()



Static StartTime As Date



Dim SecondsToCount As Integer

SecondsToCount = 15 'Set this variable to the total number of seconds to
count down

If Loops = 0 Then StartTime = Time
Min = (SecondsToCount - DateDiff("s", StartTime, Time)) \ 60
Sec = (SecondsToCount - DateDiff("s", StartTime, Time)) Mod 60
Me.TimeLeft.Caption = "Form will close in " & Min & ":" & Format(Sec,"00")

Loops = Loops + 1



If Me.TimeLeft.Caption = "Form will close in 0:00" Then
DoCmd.Close acForm, Me.Name
End If


end Sub
 
Welcome to the forums! We are the most active Microsoft Access community on the internet by far, with posts going back over 20 years!

To get started, I highly recommend you read the post below. It contains important information for all new users to this forum.

https://www.access-programmers.co.uk/forums/threads/new-member-read-me-first.223250/

We look forward to having you around here, learning stuff and having fun!
 
As you are only allowing 5 minutes, what is the point of showing 0 hours?
I would just subtract one time from another and show as whatever format you want
Code:
t=#08/10/2022 08:00:00#
? t
10/08/2022 08:00:00 
? now()-t
 0.219432870369928 
? format(now()-t,"hh:nn:ss")
05:16:59
 
Last edited:
As you are only allowing 5 minutes, what is the point of showing 0 hours?
Good question @Gasman, this is not only five min it might more than hours.. i am trying to get the same format that is my main intention.
 
Put the timer interval in the property sheet and remove the Form_Timer code from the Load event. Its not needed

You could use Mod 3600 to handle hours but I would suggest you forget using hours in your countdown.
If the countdown time is that long. it will be a distraction.

When the countdown reaches zero your form should close ...or do you want Application.Quit instead?

Perhaps it would help to look at 2 working examples on my website?

and the customised message form with timer from here
 
Last edited:
or simply:

Me.TimeLeft.Caption = "Form will close in " & "00:" & Format$(StartTime, "nn\:ss")
 
on the demo there are minutes and hours.
so Comment out (on the Code) which one to test.
 

Attachments

Hi. Welcome to AWF!

Just FYI, I moved your thread out of the Introduction forum.
 
@arnelgp This is exactly what I was looking for. However, I don't need the hour part of the format. I just need nn:ss. I am having a difficult time trying to figure that out and make it a fifteen minute timer (15:00). Any help would be appreciated.
 
@arnelgp This is exactly what I was looking for. However, I don't need the hour part of the format. I just need nn:ss. I am having a difficult time trying to figure that out and make it a fifteen minute timer (15:00). Any help would be appreciated.
Hi @BartJ

Welcome to AWF!
 
Thank you again @arnelgp. I do have one question. When the timer reaches 00:00 it loops back to 60 min timer and keeps the form open. I would like it to be a 15:00 timer. At the end of the 15 min, then close the form. How do I do that?
 
Last edited:
on the ending part of the Timer Event, change this portion to:
Code:
'If TimeValue(StartTime) = #12:00:00 AM# Then
If sFormat = "00:00" Then
    Me.TimerInterval = 0
    Loops = 0
    DoCmd.Close acForm, Me.Name, acSaveNo
End If
 

Users who are viewing this thread

Back
Top Bottom