This type of validation code belongs in the textbox BeforeUpdate event; the
AfterUpdate event is too late, and focus will simply move to the next field
if the code is done there.
If the discount field is numeric, which it usually is, this will do the job:
Private Sub txtDiscount_BeforeUpdate(Cancel As Integer)
If Me.txtDiscount > 100 Then
MsgBox ("You cannot enter values over 100")
Cancel = True
txtDiscount.SelStart = 0
txtDiscount.SelLength = Len(Me.txtDiscount)
End If
End Sub
Notice the
Cancel = True
line. This tells Access to not update the field's value, and returns focus to
the trextbox, so that the correction can be made. The lines
txtDiscount.SelStart = 0
txtDiscount.SelLength = Len(Me.txtDiscount)
hilites the incorrect data, making correction easier on the user.