Countdown Timer (1 Viewer)

MaleNurse325

Registered User.
Local time
Today, 06:24
Joined
Jan 11, 2016
Messages
67
I have a countdown to close timer on a form.
I can only make the countdown in seconds and 20 minutes is a lot of seconds.
Can anyone help me convert this to minutes and seconds please?

Private Sub Form_Timer()

TimeCount = TimeCount + 1

Me.txtCounter = 1200 - TimeCount
If TimeCount = 120 Then
Me.txtCounter.ForeColor = vbRed

End If

If TimeCount = 1201 Then
DoCmd.Quit acQuitSaveAll

End If

:banghead:
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:24
Joined
Oct 29, 2018
Messages
21,357
Hi. I don't understand the issue. 20 minutes or 1200 seconds will still run in the same amount of time. So, why does it matter if you used 20 or 1200? Just curious...
 

MaleNurse325

Registered User.
Local time
Today, 06:24
Joined
Jan 11, 2016
Messages
67
i have a field on the form with the time countdown to tell the user how long they hve before the application shuts him down. We have power issues where I work (on an oil rig) and if the programme is left running it can corrupt the database.

Sorry for not beign too clear :(
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:24
Joined
Oct 29, 2018
Messages
21,357
i have a field on the form with the time countdown to tell the user how long they hve before the application shuts him down. We have power issues where I work (on an oil rig) and if the programme is left running it can corrupt the database.

Sorry for not beign too clear :(
Okay, I think this explains the need for the timer, but I still don't understand the original question. Why were you asking to convert the number of seconds to "minutes and seconds?" What does that mean? Can you show us with examples? Thanks.
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:24
Joined
Sep 21, 2011
Messages
14,041
I *think* the o/p wants to display to the user that they have x minutes and y seconds before the DB will shutdown, as opposed to z seconds ?
 

Micron

AWF VIP
Local time
Today, 09:24
Joined
Oct 20, 2018
Messages
3,476
PMFJI - While you're at it, might be a good idea to state what the form timer interval is.


Consider also that since the form timer is based on milliseconds, it matters not if you want to use a 'smaller' number like 20 or 1200 seconds. That means the common denominator is milliseconds because that's how the timer event works. Thus any number you use for TimeCount (which is undeclared) makes no difference. Your timer interval probably needs to be 1000 anyway, or if you really want a small number for your code, it needs to be that number x 1000. Then you're basically right back where you started.


EDIT
as opposed to z seconds
In that case, divide the result of the code by 60 and show the result? Then you lose seconds, so you probably want to show the remainder of the division as well.
 

isladogs

MVP / VIP
Local time
Today, 13:24
Joined
Jan 14, 2017
Messages
18,186
Hi
To save reinventing the wheel, you could check out my Countdown Timer example app.

That can count down any time interval in minutes and seconds from a set interval of up to 1 hour. If its useful I also have another version I'm working on now that has a maximum interval of 24 hours
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:24
Joined
Oct 29, 2018
Messages
21,357
I *think* the o/p wants to display to the user that they have x minutes and y seconds before the DB will shutdown, as opposed to z seconds ?
Okay, this makes sense. If so, maybe something like:
Code:
Me.txtCounter = (1200 - TimeCount) \ 60 & " minutes and " & (1200 - TimeCount) Mod 60 & " seconds"
 

apr pillai

AWF VIP
Local time
Today, 18:54
Joined
Jan 20, 2005
Messages
735
Create a New Form with a Label Control with the Name: Label0.
Copy and Paste the following code into the Form Module.
Code:
Option Compare Database
Option Explicit

Dim x As Double, y As Integer
Private Sub Form_Load()
    x = 20: y = 60
    Me.TimerInterval = 1000
End Sub

Private Sub Form_Timer()
y = y - 1
If y > 0 Then
    Me.Label0.Caption = Format(x, "00:") & Format(y, "00")
    If x = 0 Then
        Me.TimerInterval = 0
        DoCmd.Close
    End If
Else
   x = x - 1
   Me.Label0.Caption = Format(x, "00:") & Format(y, "00")
   y = 60
End If
End Sub
Save the Form.
Open the form in Normal View.
 

Users who are viewing this thread

Top Bottom