
I am suggesting storing the seconds and hundredths in one number - I do not see
any benefit to entering 13 (seconds) in one textbox and 41 (hundredths) in a
different textbox, vs. typing 13.41 into a single textbox.
The expression I posted:
Private Sub txtMinutes_AfterUpdate()
Me!txtRacetime = NZ(Me!txtHours)*3600 + NZ(Me!txtMinutes) * 60 _
+ NZ(Me!txtSeconds)
End Sub
generates the combined number. The NZ (Null To Zero) function prevents errors
when a textbox is empty: anything plus NULL gives NULL, and the NZ function
converts the null value into a zero. There are 3600 seconds in an hour, and 60
in a minute, so I am multiplying the entered number of hours by 3600 and the
entered number of minutes by 60, and adding those two products to the number
of seconds in the third textbox.
What I am suggesting is that you have this identical expression in the
AfterUpdate event of the three textboxes, which I named txtHours, txtMinutes,
and txtSeconds. If you change any one of them, it will recalculate the sum of
the three and store the result into the textbox named txtRacetime, which would
be bound to the (currency, or decimal, or Double) race time field in your
table. It might be better to explicitly convert the calculated result to your
desired datatype: e.g. if the race time is a Currency field, use
Private Sub txtMinutes_AfterUpdate()
Me!txtRacetime = CCur(NZ(Me!txtHours)*3600) _
+ CCur(NZ(Me!txtMinutes) * 60) _
+ CCur(NZ(Me!txtSeconds))
End Sub
You would also want to do the reverse - display the hours, minutes, and
seconds when you navigate to a record which already has a time. To do so put
code in the form's Current event:
Private Sub Form_Current()
If Not IsNull(Me!txtRacetime) Then
Me!txtHours = Me!txtRacetime \ 3600
Me!txtMinutes = Me!txtRaceTime \ 60 MOD 60
Me!txtSeconds = Me!txtRaceTime - 60 * (Me!txtRacetime \ 60)
End If
End Sub
The \ is not a typo - it is the integer divide operator, so a a racetime of
128.24 seconds, integer divided by 60, is 2 minutes. The last expression gets
the remaining 8.24 seconds.
--
John W. Vinson [MVP]