Date Time Difference

  • Thread starter Thread starter RK
  • Start date Start date
R

RK

How can I create a Count down clock on a form. ie put in
an end date and time and based off the current time would
display the number of days, hours, minutes to the end
date. I tried to experiment with an excel spread sheet
with some success but cand't get it to work in Access.
Any thoughts?

Thank you.
 
Hi RK

Probably the best method is to write a function to calculate the difference
in seconds and then format the string:

Public Function CountDown(EndTime as Variant) as String
Dim lTemp as long
Dim D as Integer, H as Integer, M as Integer, S as Integer
If Not IsDate(EndTime) then Exit Function
lTemp = DateDiff("s", Now, EndTime)
S = lTemp Mod 60
lTemp = lTemp \ 60
M = lTemp Mod 60
lTemp = lTemp \ 60
H = lTemp Mod 24
D = lTemp \ 24
CountDown = D & " days, " & H & " hours, " _
& M & " minutes, " & S & " seconds"
End Function

Now, all you need is a textbox or label on your form and a Timer event which
updates it every second:

Me.txtCountDown = CountDown(txtEndTime)
 
Created
Test Boxes - txtEndTime, txtCountDown
Created Funtion (below) modCountDown
In the forms timer interval = 120

?? Me.txtCountDown = CountDown(txtEndTime), doesn't
compile
What am I messing up?

Thanks

-----Original Message-----
Hi RK

Probably the best method is to write a function to calculate the difference
in seconds and then format the string:

Public Function CountDown(EndTime as Variant) as String
Dim lTemp as long
Dim D as Integer, H as Integer, M as Integer, S as Integer
If Not IsDate(EndTime) then Exit Function
lTemp = DateDiff("s", Now, EndTime)
S = lTemp Mod 60
lTemp = lTemp \ 60
M = lTemp Mod 60
lTemp = lTemp \ 60
H = lTemp Mod 24
D = lTemp \ 24
CountDown = D & " days, " & H & " hours, " _
& M & " minutes, " & S & " seconds"
End Function

Now, all you need is a textbox or label on your form and a Timer event which
updates it every second:

Me.txtCountDown = CountDown(txtEndTime)
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand



How can I create a Count down clock on a form. ie put in
an end date and time and based off the current time would
display the number of days, hours, minutes to the end
date. I tried to experiment with an excel spread sheet
with some success but cand't get it to work in Access.
Any thoughts?

Thank you.


.
 
I just typed the code into the newsreader, but I pasted it into a module
just now and it seems to work OK. So then I created a form with textboxes
the same as you describe, and the countdown works fine.

What is the compile error you get?

BTW, you shouldn't need a timer interval lower than 1000 (1 second) because
your display will not change more often than that.
--

Graham Mandeno [Access MVP]
Auckland, New Zealand


RK said:
Created
Test Boxes - txtEndTime, txtCountDown
Created Funtion (below) modCountDown
In the forms timer interval = 120

?? Me.txtCountDown = CountDown(txtEndTime), doesn't
compile
What am I messing up?

Thanks

-----Original Message-----
Hi RK

Probably the best method is to write a function to calculate the difference
in seconds and then format the string:

Public Function CountDown(EndTime as Variant) as String
Dim lTemp as long
Dim D as Integer, H as Integer, M as Integer, S as Integer
If Not IsDate(EndTime) then Exit Function
lTemp = DateDiff("s", Now, EndTime)
S = lTemp Mod 60
lTemp = lTemp \ 60
M = lTemp Mod 60
lTemp = lTemp \ 60
H = lTemp Mod 24
D = lTemp \ 24
CountDown = D & " days, " & H & " hours, " _
& M & " minutes, " & S & " seconds"
End Function

Now, all you need is a textbox or label on your form and a Timer event which
updates it every second:

Me.txtCountDown = CountDown(txtEndTime)
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand



How can I create a Count down clock on a form. ie put in
an end date and time and based off the current time would
display the number of days, hours, minutes to the end
date. I tried to experiment with an excel spread sheet
with some success but cand't get it to work in Access.
Any thoughts?

Thank you.


.
 
Invalid outside procedure.

I placed the code

Me.txtCountDown = CountDown(txtEndTime)

in the form code (Alt f11)
and compiled it and that is the error. Should this be
placed else where?

Thanks

-----Original Message-----
I just typed the code into the newsreader, but I pasted it into a module
just now and it seems to work OK. So then I created a form with textboxes
the same as you describe, and the countdown works fine.

What is the compile error you get?

BTW, you shouldn't need a timer interval lower than 1000 (1 second) because
your display will not change more often than that.
--

Graham Mandeno [Access MVP]
Auckland, New Zealand


Created
Test Boxes - txtEndTime, txtCountDown
Created Funtion (below) modCountDown
In the forms timer interval = 120

?? Me.txtCountDown = CountDown(txtEndTime), doesn't
compile
What am I messing up?

Thanks

-----Original Message-----
Hi RK

Probably the best method is to write a function to calculate the difference
in seconds and then format the string:

Public Function CountDown(EndTime as Variant) as String
Dim lTemp as long
Dim D as Integer, H as Integer, M as Integer, S as Integer
If Not IsDate(EndTime) then Exit Function
lTemp = DateDiff("s", Now, EndTime)
S = lTemp Mod 60
lTemp = lTemp \ 60
M = lTemp Mod 60
lTemp = lTemp \ 60
H = lTemp Mod 24
D = lTemp \ 24
CountDown = D & " days, " & H & " hours, " _
& M & " minutes, " & S & " seconds"
End Function

Now, all you need is a textbox or label on your form
and
a Timer event which
updates it every second:

Me.txtCountDown = CountDown(txtEndTime)
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand



How can I create a Count down clock on a form. ie
put
in
an end date and time and based off the current time would
display the number of days, hours, minutes to the end
date. I tried to experiment with an excel spread sheet
with some success but cand't get it to work in Access.
Any thoughts?

Thank you.




.


.
 
It sounds to me like you just placed this line of code in the general
declarations section of the from code. It needs to go in the forms Timer
event.

Sue

RK said:
Invalid outside procedure.

I placed the code

Me.txtCountDown = CountDown(txtEndTime)

in the form code (Alt f11)
and compiled it and that is the error. Should this be
placed else where?

Thanks

-----Original Message-----
I just typed the code into the newsreader, but I pasted it into a module
just now and it seems to work OK. So then I created a form with textboxes
the same as you describe, and the countdown works fine.

What is the compile error you get?

BTW, you shouldn't need a timer interval lower than 1000 (1 second) because
your display will not change more often than that.
--

Graham Mandeno [Access MVP]
Auckland, New Zealand


Created
Test Boxes - txtEndTime, txtCountDown
Created Funtion (below) modCountDown
In the forms timer interval = 120

?? Me.txtCountDown = CountDown(txtEndTime), doesn't
compile
What am I messing up?

Thanks


-----Original Message-----
Hi RK

Probably the best method is to write a function to
calculate the difference
in seconds and then format the string:

Public Function CountDown(EndTime as Variant) as String
Dim lTemp as long
Dim D as Integer, H as Integer, M as Integer, S as
Integer
If Not IsDate(EndTime) then Exit Function
lTemp = DateDiff("s", Now, EndTime)
S = lTemp Mod 60
lTemp = lTemp \ 60
M = lTemp Mod 60
lTemp = lTemp \ 60
H = lTemp Mod 24
D = lTemp \ 24
CountDown = D & " days, " & H & " hours, " _
& M & " minutes, " & S & " seconds"
End Function

Now, all you need is a textbox or label on your form and
a Timer event which
updates it every second:

Me.txtCountDown = CountDown(txtEndTime)
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand



message
How can I create a Count down clock on a form. ie put
in
an end date and time and based off the current time
would
display the number of days, hours, minutes to the end
date. I tried to experiment with an excel spread sheet
with some success but cand't get it to work in Access.
Any thoughts?

Thank you.




.


.
 
Back
Top