Hello,
Im wondering why my .SetFocus is not working properly
In the code below i have if the user does not input a valid date, clear the box then i want to setfocus back into that textbox, but what it does is it DOES clear out the textbox but then it just jumps ahead to my next Tab Index ...any ideas
Edit: could it be that my first If statement is exiting the sub after clearing it?
Im wondering why my .SetFocus is not working properly
In the code below i have if the user does not input a valid date, clear the box then i want to setfocus back into that textbox, but what it does is it DOES clear out the textbox but then it just jumps ahead to my next Tab Index ...any ideas
Edit: could it be that my first If statement is exiting the sub after clearing it?
Code:
Private Sub startdatebox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If startdatebox = vbEmptyString Then Exit Sub
If IsDate(startdatebox) Then
startdatebox = Format(startdatebox, "dd/mm/yyyy")
Else
MsgBox "Please enter a valid date!" & vbNewLine & vbNewLine & "Remember you must have the forward slashes in your date." _
& vbNewLine & vbNewLine & "Example: 01/01/2018", vbCritical
startdatebox.Value = ""
startdatebox.SetFocus
End If
End Sub
Last edited: