If-Then Statement

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.
 
N

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)
 
J

John Vinson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top