If-Then Statement

  • Thread starter Thread starter Nick C
  • Start date Start date
N

Nick C

I have the following If-Then statement to generate an error when the number
of discrepancies is greater than the quantity inspected:

Private Sub cmd_Rejects_Exit(Cancel As Integer)

If Not Me.cmd_Rejects < Me.Qty_Inspected Then
MsgBox "Number Of Discrepancies Cannot Be Greater Than Quantity
Inspected!"
Me.cmd_Rejects.SetFocus
End If
End Sub

This code works well, however, it allows the user to proceed without fixing
the error. How can I correct this as to stop the user from leaving the
field until the error is corrected?

Thank you very much for your assistance in this matter.

Nick C.
 
That was PERFECT! Thanks a million!!!

Nick C.


Dirk Goldgar said:
with

Cancel = True

That's what the event procedure's Cancel argument is for -- to cancel
the event; in this case, to prevent the user from exiting the control.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
How can I correct this as to stop the user from leaving the
field until the error is corrected?

oops! Use the Control's BeforeUpdate event instead of its Exit
event... and still set Cancel to True.
 
Back
Top