G
gsnidow via AccessMonster.com
Greetings all. I am working on a simple timer for various things, which has
on a form a start/stop button, and two unbound text boxes for the start and
stop times. I am trying to calculate the number of seconds between the start
and stop times as the elapsed time. It all works with the exception of the
elapsed time, which is commented in the code. However, I can use precisely
the same format in a query, and it works fine. I am completely flumoxed.
Any ideas?
On Error GoTo Err_cmdStartStop_Click
Dim StartTime As Date
Dim StopTime As Date
Dim ElapsedTime As Integer
'Make sure user has chosen an activity to be timed
If Me.cboActivity.Value = "" Then
MsgBox ("You must choose an activity")
Exit Sub
End If
'Start and stop the clock with one button
If cmdStartStop.Caption = "Start" Then
StartTime = Now()
Me.cmdStartStop.Caption = "Stop"
Me.txtStartTime.Value = StartTime
Else
If Me.cmdStartStop.Caption = "Stop" Then
StopTime = Now()
Me.txtStopTime.Value = StopTime
Me.cmdStartStop.Caption = "Start"
Me.cmdSaveResults.Visible = True
'>>>Need help with next line
Me.txtElapsedTime = DateDiff("s", StartTime, StopTime)
End If
End If
Exit_cmdStartStop_Click:
Exit Sub
Err_cmdStartStop_Click:
MsgBox Err.Description
Resume Exit_cmdStartStop_Click
End Sub
on a form a start/stop button, and two unbound text boxes for the start and
stop times. I am trying to calculate the number of seconds between the start
and stop times as the elapsed time. It all works with the exception of the
elapsed time, which is commented in the code. However, I can use precisely
the same format in a query, and it works fine. I am completely flumoxed.
Any ideas?
On Error GoTo Err_cmdStartStop_Click
Dim StartTime As Date
Dim StopTime As Date
Dim ElapsedTime As Integer
'Make sure user has chosen an activity to be timed
If Me.cboActivity.Value = "" Then
MsgBox ("You must choose an activity")
Exit Sub
End If
'Start and stop the clock with one button
If cmdStartStop.Caption = "Start" Then
StartTime = Now()
Me.cmdStartStop.Caption = "Stop"
Me.txtStartTime.Value = StartTime
Else
If Me.cmdStartStop.Caption = "Stop" Then
StopTime = Now()
Me.txtStopTime.Value = StopTime
Me.cmdStartStop.Caption = "Start"
Me.cmdSaveResults.Visible = True
'>>>Need help with next line
Me.txtElapsedTime = DateDiff("s", StartTime, StopTime)
End If
End If
Exit_cmdStartStop_Click:
Exit Sub
Err_cmdStartStop_Click:
MsgBox Err.Description
Resume Exit_cmdStartStop_Click
End Sub