Hello Klatuu
Sorry but I'm having problems making this function work. I'm sure it's
because I am not familiar with how to set up functions. But this is what I
did.
From the property sheet of the text field [FinishTime] I clicked on the Code
Builder option for the Before Update property and this led me to a section
like this
-----
Private Sub FinishTime_BeforeUpdate(Cancel As Integer)
End Sub
-----
When I pasted your text between these two lines an extra End Function
appeared at the end and the End Sub disappeared.
When I typed into the FinishTime field on the saved form I got the error:
Compile Error: Method or Data Member Not Found
The following line was highlighted:
Private Sub FinishTime_BeforeUpdate(Cancel As Integer)
And the (Me.txtTimeBox) part of the following line was also highlighted
Me.txtTimeBox = FormatTime(Me.txtTimeBox)
I tried renaming things and chopping things out but I get all kinds of other
errors. As I say, I don't really know what I'm doing working on the code
side of things.
Can you offer any further help, or should I abandon this route, please? Thanks
ancient_hilly
Klatuu said:
Here is a function that should do most of what you need. It does not handle
hours over 99, nor does is check to see if mintues or seconds <= 60. I have
also coded it for the very best data entry speed. Instead of using the ":"
character for data entry, I have it set up to use "/". this way, the data
entry person does not have to go to the alpha keyboard, hold shift and enter
":", the "/" i on the number keypad and easy to get to. Also, nothing has to
have leading zeros. You can enter "3/3/2"
(Three Hours, Three Minutes, and Two Seconds) it will print as "03:03:02"
call it like Me.txtTimeBox = FormatTime(me.txtTimeBox)
Function FormatTime(strTime As String) As String
Dim aryTime
aryTime = Split(strTime, "/")
Select Case UBound(aryTime)
Case Is = 0
FormatTime = "00:00:" & Format(aryTime(0), "00")
Case Is = 1
FormatTime = "00:" & Format(aryTime(0), "00") & ":" &
Format(aryTime(1), "00")
Case Is = 2
FormatTime = Format(aryTime(0), "00") & ":" _
& Format(aryTime(1), "00") & ":" & Format(aryTime(2), "00")
End Select
End Function
Put it in the Lost Focust or Before Update event of your text box, depending