View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Text box in userform

Justr teasing Tim<G.

This is where my comment about rules came in, as I assumed the input could
be 2,3,4,5, or 6 characters. If it is always 6, you could simply do

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)

If KeyCode = 13 Then

Dim MyDate As Variant
With Me.TextBox1
If Len(.Value) = 6 Then
MyDate = Mid(.Value, 1, 2) & "/" & Mid(.Value, 3, 2) & "/" &
Mid(.Value, 5, 2)
If IsDate(MyDate) Then
.Text = Format(CDate(MyDate), "mm/dd/yy")
Else
MsgBox "Input is not a date"
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
End If
Else
MsgBox "Input must be 6 digits"
.SelStart = 1
.SelLength = Len(.Text)
.SetFocus
End If
End With
End If

End Sub

It goes loopy with 29th Feb 2003 as an example though.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Tim" wrote in message
...
Bob,
I meant that as a compliment, I have read some of your posts in the

past. I don't care if the textbox thinks that it a number. I just want to
get the format to be 12/34/56 or if it was text ab/cd/ef. You are correct
about what Chris has said when I read it I thought that it would owrk but
when I cahnged it to fit in to my ccode it failed. So I am still working on
it. I would think that I may have another problem in this code because I am
also going to want to do this for the time, but I will conquer that when I
get to that point. If I can get this date thing to work then the time thing
will be easy. Thanks for the help