Format year problem

  • Thread starter Thread starter Todd Huttenstine
  • Start date Start date
T

Todd Huttenstine

Private Sub TextBox1_Exit(ByVal Cancel As
MSForms.ReturnBoolean)
TextBox1.Value = Format(TextBox1.Value, "mm/dd/yyyy")
End Sub


The above code formats the textbox. There is a problem.
If I were to type in 03/12/04 and then exit the textbox,
the textbox shows 1405 for the year.

Why?

Todd Huttenstine
 
Todd,

Probably because Textboxes return text, not dates.

Try

TextBox1.Value = Format(CDate(TextBox1.Value), "mm/dd/yyyy")

HTH,
Bernie
MS Excel MVP
 
Back
Top