The following function is called by on the _Exit event of a textbox control:
P
Private Function CheckDate(ctl As control) As Boolean
Dim v As Variant
Dim b As Boolean
v = ctl.Value
b = (v = "") Or (IsDate(v)) ' null entries permitted here
If b Then
<do something not relevant to the question
Else
ctl.SetFocus
MsgBox "You must enter a valid date", vbOKOnly + vbExclamation, "Date filter"
ctl.SelStart = 0
ctl.SelLength = Len(v)
End If
CheckDate = b
End Function
The calling event sets Cancel :
.
Cancel = Not CheckDate(Me.txtMytextbox)
However ctl.Setfocus does not set the focus to the ctl and the text in the control is not selected. All that happens is that the cursor disappears entirely and the textbox still has to be selected manually. Why doesn't it work?
And, as it doesn't, how do get the cursor to return to the relevant textbox? Anybody any idea.