I have a couple of functions that do very simple validation on text boxes.
See below the code for the date check.
When I call this function, and Non Valid Date value is displayed, I want the cursor to go back to the text box that called it, hence the setfocus, But it doesnt work.
By the way I am calling the function on exit from this field.
Also in the case of the date routine, it allows dates entered as mm/dd/yyy to be entered, although they are re-displayed as dd/mm/yyyy.
Any Ideas?
Thanks
Gary
Public Sub ChkDate(ctrl As TextBox)
Dim dteDate As Variant
If Trim(ctrl.Text) <> "" Then
If IsDate(ctrl.Text) = True Then
dteDate = DateValue(ctrl.Text)
ctrl.Text = Format(dteDate, "dd/mm/yyyy"
Else
MsgBox "Non Valid Date value "
ctrl.Text = ""
ctrl.SetFocus
End If
End If
End Sub
See below the code for the date check.
When I call this function, and Non Valid Date value is displayed, I want the cursor to go back to the text box that called it, hence the setfocus, But it doesnt work.
By the way I am calling the function on exit from this field.
Also in the case of the date routine, it allows dates entered as mm/dd/yyy to be entered, although they are re-displayed as dd/mm/yyyy.
Any Ideas?
Thanks
Gary
Public Sub ChkDate(ctrl As TextBox)
Dim dteDate As Variant
If Trim(ctrl.Text) <> "" Then
If IsDate(ctrl.Text) = True Then
dteDate = DateValue(ctrl.Text)
ctrl.Text = Format(dteDate, "dd/mm/yyyy"
Else
MsgBox "Non Valid Date value "
ctrl.Text = ""
ctrl.SetFocus
End If
End If
End Sub