Countdown Clock (1 Viewer)

Snowflake68

Registered User.
Local time
Today, 08:26
Joined
May 28, 2014
Messages
452
I have a form that automatically refreshes after a set time which is set by the user. They can set the refresh rate to anything from 5 seconds to 120 seconds using a dropdown box on the same form.
This all works and I also have a text box displaying the date and time of the time the form was last refreshed. All good so far.

What I would like is another text box counting down the seconds to the next refresh but I am stuck on how to achieve this.

I have placed a subform with a clock of the current time which is working. I then tried to calculate the time that the form will next refresh by adding the current time to the refresh rate. But this is not working because adding say 10 to the current date and time are just adding 10 days and not 10 seconds.

Any ideas how to convert the current date and time into seconds so that I can just add the number of seconds and then convert it back into a date and time again.
Not sure if this work but if anyone has any other ideas I will give them a try.

Thanks
 

Attachments

  • Next Refresh.JPG
    Next Refresh.JPG
    13.8 KB · Views: 435

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:26
Joined
May 7, 2009
Messages
19,232
use DateAdd() function (google the syntax) to add minute, second, hour, days, month years, etc.
 

Snowflake68

Registered User.
Local time
Today, 08:26
Joined
May 28, 2014
Messages
452
use DateAdd() function (google the syntax) to add minute, second, hour, days, month years, etc.
I already do this to get the date in the legible format like this but I want to convert it back to total number of seconds first.

Code:
=Format(Now(),"dddd") & " " & DayString(Now()) & " " & Format(Now(),"mmmm yyyy") & "  " & Format(Now(),"hh:nn:ss")
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:26
Joined
Oct 29, 2018
Messages
21,454
I already do this to get the date in the legible format like this but I want to convert it back to total number of seconds first.

Code:
=Format(Now(),"dddd") & " " & DayString(Now()) & " " & Format(Now(),"mmmm yyyy") & "  " & Format(Now(),"hh:nn:ss")
You can store the last refresh time in a hidden Textbox.
 

Snowflake68

Registered User.
Local time
Today, 08:26
Joined
May 28, 2014
Messages
452
You can store the last refresh time in a hidden Textbox.
I am doing this, I dont think I am explaining well enough for people to understand me.

I need to add 10 seconds to the last refresh time but it just adds 10 days and I cannot figure out how to add just seconds to a date and time. And then I just need to count down the seconds to the next refresh.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:26
Joined
May 7, 2009
Messages
19,232
is this near or far?
 

Attachments

  • refreshTime.accdb
    576 KB · Views: 456

theDBguy

I’m here to help
Staff member
Local time
Today, 00:26
Joined
Oct 29, 2018
Messages
21,454
I am doing this, I dont think I am explaining well enough for people to understand me.

I need to add 10 seconds to the last refresh time but it just adds 10 days and I cannot figure out how to add just seconds to a date and time. And then I just need to count down the seconds to the next refresh.
As @arnelgp suggested, you simply use the DateAdd() function to your stored refreshed time. For example:

Code:
DateAdd("s",10,Me.HiddenTextboxName)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 02:26
Joined
Feb 28, 2001
Messages
27,140
Just as a word of warning... timers are good when you need them. But because they are "interrupt" events they can interfere with form and code operation. When you open a form, you get a sequence of events - OnOpen, OnLoad, OnActivate, OnEnter, OnCurrent - and that sequence is fixed. Until the timer comes along. A timer cannot interrupt an active event - but it can insert itself between other pending events that are part of a sequence. You were wise to limit the values to drop-downs and to make the smallest interval 5 seconds. Even so, the more you add to the timer event's list of things to do, the more interference you trigger in other events that might be deferred because the timer just clicked.

I'm not saying don't use timers. Just be careful on how much you want them to do.
 

Snowflake68

Registered User.
Local time
Today, 08:26
Joined
May 28, 2014
Messages
452
is this near or far?
I have got this working on my main form by making the main form refresh when the Next Refresh hits zero but I also want to be able to stop the refresh from running. So if they select 0 it stops the timer event. This isnt working and if I select 0 it just keeps refreshing in a constant loop that I cannot get out of without closing the application.

Im off to watch England v Germany now so will revisit this in the morning.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:26
Joined
May 7, 2009
Messages
19,232
Im off to watch England v Germany now so will revisit this in the morning
how was the game, i hope you bet on any side, otherwise just watching is boring.
 

Attachments

  • refreshTime.accdb
    580 KB · Views: 465

Users who are viewing this thread

Top Bottom