View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default User Forms data entry - MM/DD/YYYY

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim cDelim As Long
cDelim = Len(TextBox1.Text) - Len(Replace(TextBox1.Text, "/", ""))
Select Case KeyAscii
Case Asc("0") To Asc("9"): 'OK
Case Asc("/"):
If cDelim = 2 Then
KeyAscii = 0
Else
cDelim = cDelim + 1
End If
Case Else: KeyAscii = 0
End Select

End Sub

This can be amended to be more specific

--

HTH

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


"UmpaL00mpa" wrote in message
...
I have a custom user form that pops up during one of the macros I run. In

one
text box the user has to enter a date. I would like to write some code so

that
the user can only enter the date in the MM/DD/YYYY format - eg.

11/07/2004.
What is the VBA code for this? Any help would by appreciated. Thank you.