PDA

View Full Version : Solved: how can a textbox with date returns to the same textbox after error handler.



lehgzil
09-21-2010, 09:08 PM
good day again,
i have this code which checks the value of the textbox if its a date and if so, prints it out on the same textbox as short date. i have it with an error handler which brings a message box allerting the user of miswriting.

what i cant understand and im trying to do is that when the error occured(user typed a non date value) after the message box prompt it returns to the same textbox for reentry.

i had tried removing the first if, the with block and substituting its exit event to change and click event.
vba:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox1 = vbNullString Then Exit Sub

If IsDate(TextBox1) Then
TextBox1 = Format(TextBox18, "short date")
Else

MsgBox "Non valid date"
Cancel = False
With TextBox1
.Value = vbNullString
End With
End If
End Sub

hoping for some help, thanks

Bob Phillips
09-22-2010, 01:40 AM
Set Cancel=True not False on an error.

lehgzil
10-01-2010, 01:19 AM
ok tested and tried. it works thanks sir xld.