User Forms data entry - MM/DD/YYYY

  • Thread starter Thread starter UmpaL00mpa
  • Start date Start date
U

UmpaL00mpa

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.

(e-mail address removed)
 
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top