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

libin04

New member
Local time
Today, 21:09
Joined
Aug 10, 2022
Messages
14
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
 

Jon

Access World Site Owner
Staff member
Local time
Today, 21:09
Joined
Sep 28, 1999
Messages
7,398
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!
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:09
Joined
Sep 21, 2011
Messages
14,310
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:

libin04

New member
Local time
Today, 21:09
Joined
Aug 10, 2022
Messages
14
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.
 

isladogs

MVP / VIP
Local time
Today, 21:09
Joined
Jan 14, 2017
Messages
18,229
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:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:09
Joined
May 7, 2009
Messages
19,245
see your code in action.
 

Attachments

  • FormCountDown.accdb
    480 KB · Views: 136

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:09
Joined
May 7, 2009
Messages
19,245
or simply:

Me.TimeLeft.Caption = "Form will close in " & "00:" & Format$(StartTime, "nn\:ss")
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:09
Joined
May 7, 2009
Messages
19,245
on the demo there are minutes and hours.
so Comment out (on the Code) which one to test.
 

Attachments

  • FormCountDown.accdb
    912 KB · Views: 133

theDBguy

I’m here to help
Staff member
Local time
Today, 13:09
Joined
Oct 29, 2018
Messages
21,474
Hi. Welcome to AWF!

Just FYI, I moved your thread out of the Introduction forum.
 

BartJ

New member
Local time
Today, 16:09
Joined
Sep 1, 2022
Messages
3
@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.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:09
Joined
Oct 29, 2018
Messages
21,474
@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!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:09
Joined
May 7, 2009
Messages
19,245
this is the timer with nn:ss format.
 

Attachments

  • FormCountDown.accdb
    912 KB · Views: 124

BartJ

New member
Local time
Today, 16:09
Joined
Sep 1, 2022
Messages
3
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:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:09
Joined
May 7, 2009
Messages
19,245
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

Top Bottom