View Single Post
  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

Phil,

Here is one way, a bit kludgy but it works in full HH:MM mode

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim fColon As Boolean
Dim iPos As Long

iPos = InStr(1, TextBox1.Value, ":")
fColon = iPos 0
Select Case KeyAscii
Case 48 To 57: ' 0-9
Case 58: 'colon
If fColon Then
KeyAscii = 0 'colon already entered
End If
Case Else:
KeyAscii = 0
Exit Sub
End Select

If Len(TextBox1.Text) = 0 Or Len(TextBox1.Text) = 3 Then
If KeyAscii Asc("5") Then
KeyAscii = 0
Exit Sub
End If
ElseIf Len(TextBox1.Text) = 1 Then
'nothing to do
ElseIf Len(TextBox1.Text) = 2 Then
If KeyAscii Asc(":") Then
KeyAscii = 0
Exit Sub
End If
End If

End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Phil" wrote in message
. uk...
How can i set a userform textbox properties so i can enter HH:MM.?

Thanks