trapping date format in text box


Posted by Chris on July 18, 2001 9:21 PM

can anyone tell me how I can trap the text entered in a text box?

I want it to follow the format:
mm/dd/yy


-Chris

Posted by Connie on July 19, 2001 6:31 AM

What do you mean by "trap"? Please clarify (n/t)

Posted by Cory on July 19, 2001 6:48 AM

Try this...

TextBox1.Text = Format(TextBox1.Text, "mm/dd/yy")

I use this in the TextBox "Exit" handler, but you can put it where you want...

Any help?

Cory

Posted by Chris on July 19, 2001 7:09 AM

Re: What do you mean by "trap"? Please clarify (n/t)

I am trying to keep the data entered in 2 text boxes consistent with the format (mm/dd/yy) so that VB can do a calculation of the number of days between the two dates (txt1.value - txt2.value). I get debug errors when I enter a letter though...

does this sound like something I need to do w/trapping?

-Chris



Posted by Cory on July 19, 2001 7:30 AM

OK, how 'bout this...

If Len(TextBox1.Text) < 1 Then Exit Sub
If Asc(Right(TextBox1.Text, 1)) < 48 Or _
Asc(Right(TextBox1.Text, 1)) > 57 Then
TextBox1.Text = Left(TextBox1.Text, Len(TextBox1.Text) - 1)
End If
TextBox1.Text = Format(TextBox1.Text, "mm/dd/yy")

The first part won't allow the user to enter anything but a number. The 2nd part formats it as a date in the format you need...

That do it?

Cory