I'm using this code to evaluate the value of a textbox on a UF. If the value is invalid, a msgbox is triggered. Once the EU clicks the OK button, I want the focus back on the offending textbox. Instead, the focus is moving to the next textbox, which also has similar validation occurring, so when the EU goes back to correct the offending value, they get an error for exiting the textbox they just left.
I've researched this, and every post I've seen has txtbox.setfocus, which I have; so I'm not sure why it's not working. In theory, I could put this code in a different spot, so that it's checked after the EU clicks a cmd button, but I've yet to find a way to validate that a textbox value is ##/##/##. ISDATE doesn't work, so I'm having to evaluate the contents twice.
Thoughts?
I've researched this, and every post I've seen has txtbox.setfocus, which I have; so I'm not sure why it's not working. In theory, I could put this code in a different spot, so that it's checked after the EU clicks a cmd button, but I've yet to find a way to validate that a textbox value is ##/##/##. ISDATE doesn't work, so I'm having to evaluate the contents twice.
Thoughts?
Code:
[Private Sub txt_DoB_Exit(ByVal Cancel As MSForms.ReturnBoolean)
'Validates that the field value is a date, and converts it to MM/DD/YY format. _
If the field value is not a date, an error is thrown.
Dim Response As VbMsgBoxResult
Dim IsOk As Boolean
IsOk = True
If IsDate(Me.txt_DoB.Value) Then
Me.txt_DoB = Format(Me.txt_DoB.Value, "MM/DD/YY")
Else
MsgBox "Please enter a valid DoB, in MM/DD/YY format."
If Response = vbOK Then Me.txt_DoB.SetFocus
Exit Sub
IsOk = False
End If
End Sub/CODE]