hh:mm:ss on a timer

N

Nick T

Hi,
Sorry this is long winded, but help will be appreciated:
Have a form with various timers on it. The value of the timer is set by (a)
the on open event and then (b) a cmd button click event - this cmd button
when clicked sets my form timer to a specified amount (in its code) which
then starts to count down (from this amount).
Iv posted my code below, with the hope that somone may be able to help. I
need my timer to be in hh:mm:ss - at the moment, with the code im using (as
below) if i want my timer value to be 02:30:00 (ie 2hrs, 30mins) i put 9000
(seconds) into my cmd buttons event, howeve this is displayed in my timer as
00:0149:59 how can i change this??

My code is:

In my declaration:
Option Compare Database
Option Explicit
Dim dteStartTime1 As Date
Dim dteStartTime2 As Date
Dim varCounter As Variant

My on open event is:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Err_Open_Click

DoCmd.GoToRecord , , acLast

dteStartTime1 = DateAdd("s", 10, Now())
Me.TimerInterval = 1000
Me.Text4 = ""
Me.Text4.BackColor = vbWhite

dteStartTime2 = DateAdd("s", 10, Now())
Me.Text5 = ""
Me.Text5.BackColor = vbWhite

Exit_Open_Click:
Exit Sub

Err_Open_Click:
MsgBox Err.Description
End Sub



My on Timer code is:
Private Sub Form_Timer()

If DateDiff("s", Now, dteStartTime1) < 0 Then
Me.Text4 = "Check Required"
Me.Text4.BackColor = vbRed
Me.Overdueby.Visible = True
Me.LastInspectionOverDueBy.Visible = False



varCounter = "00:0" & Int(DateDiff("s", dteStartTime1, Now) / 60)
varCounter = varCounter & ":" _
& Right("0" & DateDiff("s", dteStartTime1, Now) Mod 60, 2)
Me.Timer2 = varCounter



Else
varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime1) / 60)
varCounter = varCounter & ":" _
& Right("0" & DateDiff("s", Now, dteStartTime1) Mod 60, 2)
Me.Timer1 = varCounter

End If


If DateDiff("s", Now, dteStartTime2) < 0 Then
Me.Text5 = "Check Required"
Me.Text5.BackColor = vbRed
Me.OverduebyWt.Visible = True
Me.LastInspectionOverDueByWt.Visible = False



varCounter = "00:0" & Int(DateDiff("s", dteStartTime2, Now) / 60)
varCounter = varCounter & ":" _
& Right("0" & DateDiff("s", dteStartTime2, Now) Mod 60, 2)
Me.Timer4 = varCounter



Else
varCounter = "00:0" & Int(DateDiff("s", Now, dteStartTime2) / 60)
varCounter = varCounter & ":" _
& Right("0" & DateDiff("s", Now, dteStartTime2) Mod 60, 2)
Me.Timer3 = varCounter

End If


End Sub


My cmd button code is:
Private Sub WtCheck_Click()
On Error GoTo Err_WtCheck_Click

dteStartTime2 = DateAdd("s", 9000, Now())
Me.TimerInterval = 1000
Me.Text5 = ""
Me.Text5.BackColor = vbWhite
Me.OverduebyWt.Visible = False
Me.LastInspectionOverDueByWt.Visible = True



Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "WeightCheckForm"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_WtCheck_Click:
Exit Sub

Err_WtCheck_Click:
MsgBox Err.Description
Resume Exit_WtCheck_Click
End Sub


Hope to hear back.
 
N

Nick T

Hiya,
Sorry, should have checked back! - seen it now & its sorted - working
perfectly.
Thanks for the help.

......until next time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top