Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default TextBox to time

Is there any way, as you exit a textbox, the value displayed in the
TextBox could be changed to the time format hh:mm (24 hour)?

So if someone entered 800 in textbox1, when they exit the textbox, textbox1
would display 08:00, but if they entered 08:00 the format would not be
changed.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default TextBox to time

You can trap the input to ensure they do input as time

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With Me.TextBox1

Select Case True

Case Len(.Text) = 2 And KeyAscii = 58 'ok
Case Len(.Text) = 5 And KeyAscii = 58 'ok
Case Len(.Text) <= 2 And KeyAscii = 48 And KeyAscii <= 57 'ok
Case (Len(.Text) = 3 Or Len(.Text) = 4) And KeyAscii = 48 And
KeyAscii <= 57 'ok
Case (Len(.Text) = 6 Or Len(.Text) = 7) And KeyAscii = 48 And
KeyAscii <= 57 'ok
Case Else: KeyAscii = 0
End Select
End With
End Sub

this could be extended to only allow w4 hours, 60 mins, 60 secs

--
__________________________________
HTH

Bob

"Patrick C. Simonds" wrote in message
...
Is there any way, as you exit a textbox, the value displayed in the
TextBox could be changed to the time format hh:mm (24 hour)?

So if someone entered 800 in textbox1, when they exit the textbox,
textbox1
would display 08:00, but if they entered 08:00 the format would not be
changed.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default TextBox to time

This did not work. But it also is not exactly what I am looking for.

I want to allow them to enter the time as 800 or 0800 and when they exit the
textbox have the inputted value be changed to (and displayed in the textbox
as) 08:00.

I need this to happen before the result is put on the worksheet because I
want to use the values of the textbox's to calculate a result that is
displayed on the UserForm.


"Bob Phillips" wrote in message
...
You can trap the input to ensure they do input as time

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With Me.TextBox1

Select Case True

Case Len(.Text) = 2 And KeyAscii = 58 'ok
Case Len(.Text) = 5 And KeyAscii = 58 'ok
Case Len(.Text) <= 2 And KeyAscii = 48 And KeyAscii <= 57
'ok
Case (Len(.Text) = 3 Or Len(.Text) = 4) And KeyAscii = 48 And
KeyAscii <= 57 'ok
Case (Len(.Text) = 6 Or Len(.Text) = 7) And KeyAscii = 48 And
KeyAscii <= 57 'ok
Case Else: KeyAscii = 0
End Select
End With
End Sub

this could be extended to only allow w4 hours, 60 mins, 60 secs

--
__________________________________
HTH

Bob

"Patrick C. Simonds" wrote in message
...
Is there any way, as you exit a textbox, the value displayed in the
TextBox could be changed to the time format hh:mm (24 hour)?

So if someone entered 800 in textbox1, when they exit the textbox,
textbox1
would display 08:00, but if they entered 08:00 the format would not be
changed.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default TextBox to time

Okay, you could try

Private Sub TextBox1_AfterUpdate()

TextBox1.Text = Format(Application.Text(Replace(TextBox1.Text, ":", ""),
"00\:00"), "hh:mm")
End Sub

but this is flawed, they could enter 1761 for instance

--
__________________________________
HTH

Bob

"Patrick C. Simonds" wrote in message
...
This did not work. But it also is not exactly what I am looking for.

I want to allow them to enter the time as 800 or 0800 and when they exit
the textbox have the inputted value be changed to (and displayed in the
textbox as) 08:00.

I need this to happen before the result is put on the worksheet because I
want to use the values of the textbox's to calculate a result that is
displayed on the UserForm.


"Bob Phillips" wrote in message
...
You can trap the input to ensure they do input as time

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With Me.TextBox1

Select Case True

Case Len(.Text) = 2 And KeyAscii = 58 'ok
Case Len(.Text) = 5 And KeyAscii = 58 'ok
Case Len(.Text) <= 2 And KeyAscii = 48 And KeyAscii <= 57 'ok
Case (Len(.Text) = 3 Or Len(.Text) = 4) And KeyAscii = 48 And
KeyAscii <= 57 'ok
Case (Len(.Text) = 6 Or Len(.Text) = 7) And KeyAscii = 48 And
KeyAscii <= 57 'ok
Case Else: KeyAscii = 0
End Select
End With
End Sub

this could be extended to only allow w4 hours, 60 mins, 60 secs

--
__________________________________
HTH

Bob

"Patrick C. Simonds" wrote in message
...
Is there any way, as you exit a textbox, the value displayed in the
TextBox could be changed to the time format hh:mm (24 hour)?

So if someone entered 800 in textbox1, when they exit the textbox,
textbox1
would display 08:00, but if they entered 08:00 the format would not be
changed.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default TextBox to time

Thank you

That work great. As to your other comment. They are pretty use to entering
the times (they just were complaining about having to enter the : ) But
you are correct they could mistype a number. Not sure how I will deal with
that problem. I guess I will see if it becomes an issue.


"Bob Phillips" wrote in message
...
Okay, you could try

Private Sub TextBox1_AfterUpdate()

TextBox1.Text = Format(Application.Text(Replace(TextBox1.Text, ":",
""), "00\:00"), "hh:mm")
End Sub

but this is flawed, they could enter 1761 for instance

--
__________________________________
HTH

Bob

"Patrick C. Simonds" wrote in message
...
This did not work. But it also is not exactly what I am looking for.

I want to allow them to enter the time as 800 or 0800 and when they exit
the textbox have the inputted value be changed to (and displayed in the
textbox as) 08:00.

I need this to happen before the result is put on the worksheet because I
want to use the values of the textbox's to calculate a result that is
displayed on the UserForm.


"Bob Phillips" wrote in message
...
You can trap the input to ensure they do input as time

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
With Me.TextBox1

Select Case True

Case Len(.Text) = 2 And KeyAscii = 58 'ok
Case Len(.Text) = 5 And KeyAscii = 58 'ok
Case Len(.Text) <= 2 And KeyAscii = 48 And KeyAscii <= 57
'ok
Case (Len(.Text) = 3 Or Len(.Text) = 4) And KeyAscii = 48
And KeyAscii <= 57 'ok
Case (Len(.Text) = 6 Or Len(.Text) = 7) And KeyAscii = 48
And KeyAscii <= 57 'ok
Case Else: KeyAscii = 0
End Select
End With
End Sub

this could be extended to only allow w4 hours, 60 mins, 60 secs

--
__________________________________
HTH

Bob

"Patrick C. Simonds" wrote in message
...
Is there any way, as you exit a textbox, the value displayed in the
TextBox could be changed to the time format hh:mm (24 hour)?

So if someone entered 800 in textbox1, when they exit the textbox,
textbox1
would display 08:00, but if they entered 08:00 the format would not be
changed.








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 343
Default TextBox to time

Sorry, but I am still having a problem. The code you gave me did exactly
what I asked it to do, but when my TextBox12_Exit code runs (see cod below),
I get a Type Mismatch error.



Private Sub TextBox11_AfterUpdate()

TextBox11.Value = Format(Application.Text(Replace(TextBox11.Value, ":",
""), "00\:00"), "hh:mm")

End Sub


Private Sub TextBox12_AfterUpdate()

TextBox12.Value = Format(Application.Text(Replace(TextBox12.Value, ":",
""), "00\:00"), "hh:mm")

End Sub



Private Sub TextBox12_Exit(ByVal Cancel As MSForms.ReturnBoolean)

TextBox13.Text = (TextBox12.Value - TextBox11.Value) * 24

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Textbox for accepting TIME WLMPilot Excel Programming 16 January 8th 08 06:58 PM
How do I format a textbox with time Jennifer Excel Programming 1 July 13th 06 06:27 AM
format textbox to time ASU Excel Discussion (Misc queries) 3 June 7th 06 10:05 PM
TextBox and Time Soniya[_4_] Excel Programming 2 December 3rd 05 07:17 AM
Format As TIME In A TextBox Minitman[_4_] Excel Programming 4 February 9th 05 12:55 AM


All times are GMT +1. The time now is 04:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"