This code is supposed to alert user and allow them to change the value if the last two characters are not a 20 or a 40. Instead of staying in the field, the cursor moves to the next field. When I stepped through the code, it seemed to be working (sets focus and highlights portion of text to be edited), however when code hits End Sub, then focus moved to next field.
Code:
Private Sub txtCurrentTerm_AfterUpdate()
If Right(Me.txtCurrentTerm, 2) <> "20" Or Right(Me.txtCurrentTerm, 2) <> "40" Then
Me.txtCurrentTerm.SetFocus
Me.txtCurrentTerm.SelStart = 4
Me.txtCurrentTerm.SelLength = 2 ' Length of selection
MsgBox Me.txtCurrentTerm & " is not a valid term. Please enter term as a 4 digit year and " & _
"academic period as 20 for Spring or 40 for Summer and Fall. " & vbCrLf & _
"Example: 200840", vbOKOnly, "Invalid Term/Academic Period"
End If
End Sub