PC Review


Reply
Thread Tools Rate Thread

Adding timer to text box

 
 
=?Utf-8?B?R3JlZw==?=
Guest
Posts: n/a
 
      26th Oct 2007
I have a subform where I am calculating time difference between current time
and the last update. I have a text box txtTimeDiff with control source
=ElapsedTimeString([Last Update],Now())

Is it possible to add timer so this text box and time difference can be
updated every second?


Here is ElapsedTimeString function
Public Function ElapsedTimeString(Date1 As Date, _
Date2 As Date) _
As String

Dim interval As Double, str As String, days As Variant
Dim hours As String, Minutes As String, seconds As String

If IsNull(Date1) = True Or _
IsNull(Date2) = True Then Exit Function

interval = Date2 - Date1
days = Fix(CSng(interval))
hours = Format(interval, "h")
Minutes = Format(interval, "n")
seconds = Format(interval, "s")



' Hours part of the string
str = str & IIf(hours = "0", "", _
IIf(hours = "1", hours & " Hour", hours & " Hours"))
str = str & IIf(hours = "0", "", _
IIf(Minutes & seconds <> "00", ", ", " "))

' Minutes part of the string
str = str & IIf(Minutes = "0", "", _
IIf(Minutes = "1", Minutes & " Minute", _
Minutes & " Minutes"))

str = str & IIf(Minutes = "0", "", _
IIf(seconds <> "0", ", ", " "))

'Seconds part of the string
str = str & IIf(seconds = "0", "", _
IIf(seconds = "1", seconds & " Second", _
seconds & " Seconds"))


If seconds > 30 Then Minutes = Minutes + 1
If Minutes > 59 Then hours = hours + 1: Minutes = 0

ElapsedTimeString = IIf(str = "", "0", str)


End Function


 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      26th Oct 2007
On Thu, 25 Oct 2007 18:59:00 -0700, Greg <(E-Mail Removed)>
wrote:

>Is it possible to add timer so this text box and time difference can be
>updated every second?


Not to the textbox, but you can use the Form's Timer event. Set the form's
Timer property to 1000 (milliseconds, to fire the event once a second) and its
On Timer event to code which sets the value of the textbox to your function.

John W. Vinson [MVP]
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a timer to a presentation? Integrity is Everything! Microsoft Powerpoint 1 10th Dec 2008 11:23 AM
Adding a timer to PP using VBA BryanM Microsoft Powerpoint 4 16th Jan 2007 10:16 PM
Adding the VB Timer Control... =?Utf-8?B?RGluZXNo?= Microsoft Excel Programming 2 9th Jan 2006 02:06 AM
Adding a timer in VBA code =?Utf-8?B?U3R1Sm9s?= Microsoft Access Form Coding 7 8th Jan 2006 09:26 PM
Adding a Timer Control Syed Zeeshan Haider Microsoft Excel Programming 5 24th Apr 2004 12:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:56 AM.