If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Input times with leading zeros
Hello, I have a race results program for a charity which needs changing.
The race is longer this year so I need to include hours (as well as mins and seconds) to be stored in the format "01:23:45" so that fastest times can be listed. I want to keep data inputting to the minimum for speed, so that when a time is, say, 24:35 I will not have to type in the leading zeros for the hours. I've tried all sorts of masks and data types, but no success so far. Can anyone please suggest a solution? Thank you. |
#2
|
|||
|
|||
Dear Klatuu
Thank you for this. I can't try it out until late tomorrow, but it looks great. I'll let you know how it works out. "Klatuu" wrote: 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 on whether you are using an unbound or bound form. (Lost Focus for unbound) "ancient_hilly" wrote: Hello, I have a race results program for a charity which needs changing. The race is longer this year so I need to include hours (as well as mins and seconds) to be stored in the format "01:23:45" so that fastest times can be listed. I want to keep data inputting to the minimum for speed, so that when a time is, say, 24:35 I will not have to type in the leading zeros for the hours. I've tried all sorts of masks and data types, but no success so far. Can anyone please suggest a solution? Thank you. |
#3
|
|||
|
|||
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 on whether you are using an unbound or bound form. (Lost Focus for unbound) "ancient_hilly" wrote: Hello, I have a race results program for a charity which needs changing. The race is longer this year so I need to include hours (as well as mins and seconds) to be stored in the format "01:23:45" so that fastest times can be listed. I want to keep data inputting to the minimum for speed, so that when a time is, say, 24:35 I will not have to type in the leading zeros for the hours. I've tried all sorts of masks and data types, but no success so far. Can anyone please suggest a solution? Thank you. |
#4
|
|||
|
|||
Post all the code in the Finish Time Before Update Event. It is just a
matter of syntax. I will be happy to fix it for you. "ancient_hilly" wrote: 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" wrote: 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 on whether you are using an unbound or bound form. (Lost Focus for unbound) "ancient_hilly" wrote: Hello, I have a race results program for a charity which needs changing. The race is longer this year so I need to include hours (as well as mins and seconds) to be stored in the format "01:23:45" so that fastest times can be listed. I want to keep data inputting to the minimum for speed, so that when a time is, say, 24:35 I will not have to type in the leading zeros for the hours. I've tried all sorts of masks and data types, but no success so far. Can anyone please suggest a solution? Thank you. |
#5
|
|||
|
|||
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" wrote: 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 on whether you are using an unbound or bound form. (Lost Focus for unbound) "ancient_hilly" wrote: Hello, I have a race results program for a charity which needs changing. The race is longer this year so I need to include hours (as well as mins and seconds) to be stored in the format "01:23:45" so that fastest times can be listed. I want to keep data inputting to the minimum for speed, so that when a time is, say, 24:35 I will not have to type in the leading zeros for the hours. I've tried all sorts of masks and data types, but no success so far. Can anyone please suggest a solution? Thank you. |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
leading zeros in text format | BigBrook | General Discussion | 5 | December 11th, 2008 08:00 PM |
leading zeros | KT | Running & Setting Up Queries | 1 | January 31st, 2005 07:49 PM |
Crystal Reports Export to Excel - Retaining Leading Zeros | CR-Tech | General Discussion | 1 | November 1st, 2004 06:15 PM |
Leading zeros disappear when saving as .csv | Theodore Bartley | General Discussion | 3 | October 31st, 2004 07:32 PM |
How do I show leading zeros in a number field | tfinklea | Database Design | 1 | August 11th, 2004 07:30 PM |