Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Countdown Timer On Access Form

Status
Not open for further replies.

nwprog

Technical User
Nov 19, 2007
24
US
I'm trying to create a count down based on two variables. The first is the current time, the second is a departure time that is entered by the operator. The code I have so far is listed below.

Private Sub txtdeptime_LostFocus()

Dim currtime As Date
Dim deptime As Date
Dim split As Date

currtime = CDate(Me.txtcurrtime.Value)
deptime = CDate(Me.txtdeptime.Value)
split = ElapsedTime(deptime, currtime)

Me.txtsplittime.Value = Format(split, "hh:nn:ss")

End Sub

Function ElapsedTime(currtime As Date, deptime As Date) As Date

ElapsedTime = deptime - currtime

End Function

Two things are going wrong. First, my currtime is base on the Time() function and before this code, it kept the current time, now it displays the time that the form opened and then stops. Second, I can't figure out how to get the clock to count back to zero minutes and seconds. I've tried several things including DateDiff and DateAdd("ss",-1, "split"), but I just can't make it work. I'm assuming it has something to do with aggragate's, but I'm not sure how to code this to make it work, can anyone help?
 
Your thread title actually points you in the right direction! In order to get the clock to do anything other than display the time when it was first invoked, you'll have to involve the form's Timer event! I usually set the Timer Interval to 1000, which means it fires once per second, but you may need to play with this value, depending on the speed of your box. Then place your Time() code in the Sub Form_Timer()

Code:
Private Sub Form_Timer()
 Me.txtcurrtime = Time()'Time display
End Sub

should update the field txtcurrtime with the current time at whatever interval you've set. You'll need to place your code for doing the countdown thing in this same sub. I'd probably use DateDiff between the two times involved to get this.

Good Luck!

Linq

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Thanks for the info, that actually worked, the current time now runs continually and the function returns the difference in time. However, I still can't make the thing count back. I've been trying to use the DateDiff function, but it doesn't like the word deptime, can you help with this. From what I know of the function, it requires an actual numberical integer along with the date. Any suggestions?

Me.txtsplittime.Value = DateDiff("ss", -1, split)
 
I wish I knew how to flag this as solved because I finally got the thing to work tonight. Thanks for the help.
 
Glad you got it working! Two things though:

First, forum etiquette requires that when you solve a problem, you post the solution. This allows others who come along researching the same/sililar issues to benefit from the solution.

Secondly, in later versions of Access there is a function named Split(). If your app is ever run in one of these later versions you're apt to run into some big time problems because of this, so you need to change the name of your varialbe! Doesn't have to be much of a change! Can be as simple as going from split to ssplit!

Good Luck!

Linq

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top