sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,373
- Office Version
-
- 2016
- Platform
-
- Windows
I'm using this to format a Textbox as a time value;
Is there a way I can make sure that the time that is entered is an actual time and if not get a message prompting to enter a new time?
Also, I want to allow numerical key presses and a backspace so they can clear the box if they want to but no other key presses permitted. At the moment I'm getting an error if I try to clear the Textbox with a backspace.
Code:
Private Sub txttime_Change()
Dim T As Date
If Len(txttime.Value) = 4 Then
On Error Resume Next
T = TimeSerial(Left(txttime.Value, 2), Right(txttime.Value, 2), 0)
On Error GoTo 0
ElseIf Len(txttime.Value) = 5 Then
On Error Resume Next
T = TimeValue(txttime.Value)
On Error GoTo 0
End If
If T > 0 Then
txttime.Value = Format(T, "hh:mm")
End If
If KeyCode = vbKeyTab Then
End If
End Sub
Is there a way I can make sure that the time that is entered is an actual time and if not get a message prompting to enter a new time?
Also, I want to allow numerical key presses and a backspace so they can clear the box if they want to but no other key presses permitted. At the moment I'm getting an error if I try to clear the Textbox with a backspace.