Smithgall
Board Regular
- Joined
- May 24, 2006
- Messages
- 68
i have a text box that allows a user to enter a date. I want them to enter it as 041670 I then handle the input according and print out April 16, 1970.
However is they enter something else such as 04161970 i get an errror. To combat that i have the following code.
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox3.Value Like "[0-9][0-9][0-9][0-9][0-9][0-9]" Then
TextBox3 = Format(TextBox3.Value, "00-00-00")
TextBox3.Value = Format(TextBox3.Value, "mmmm dd, yyyy")
Else
MsgBox "Date must be entered as MMDDYY", vbOKOnly + bCritical
Me.TextBox3 = ""
Me.TextBox3.SetFocus
End If
End Sub
it works great EXCEPT the setfocus does not work. after the msgbox is clicked textbox3 does clear but the focus go to the next textbox. I thought the code Me.TextBox3.SetFocus was fairly straightforward but doesnt seem to work. BTW i originally did it with the ME but added it in an attempt to figure it out so i dont thing that is problem.
However is they enter something else such as 04161970 i get an errror. To combat that i have the following code.
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox3.Value Like "[0-9][0-9][0-9][0-9][0-9][0-9]" Then
TextBox3 = Format(TextBox3.Value, "00-00-00")
TextBox3.Value = Format(TextBox3.Value, "mmmm dd, yyyy")
Else
MsgBox "Date must be entered as MMDDYY", vbOKOnly + bCritical
Me.TextBox3 = ""
Me.TextBox3.SetFocus
End If
End Sub
it works great EXCEPT the setfocus does not work. after the msgbox is clicked textbox3 does clear but the focus go to the next textbox. I thought the code Me.TextBox3.SetFocus was fairly straightforward but doesnt seem to work. BTW i originally did it with the ME but added it in an attempt to figure it out so i dont thing that is problem.