Validation on Form Close

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I do a validation on a Form Close to check for 2 qties to match, If they
don't match I give a message and I want the Form to stay Open. Unfortunately
the form closes. My VBA code is below:

Private Sub Form_Close()
On Error GoTo ProcError

If Me.[txtQtyA] <> Me.[txtTotQty] Then
MsgBox "Qty Not Equal - Pse Correct"
End If

Can somebody show me what to do.
Thanks
Dan
 
You can't stop the form closing, from the Close event. It's too late by
then. You need to use the Unload event. Set the Cancel parameter to
True, if you want to stop the form closing.

Private Sub Form_Unload(Cancel As Integer)
if ... then
' stop the form closing!
Cancel = True
endif
End Sub

*BUT* This is way too late for normal data validation! The user might
have saved 50 new records before he closes the form. All those records
will be saved *before* your validation code has run. For validation of
the type that you describe, you should really be using the Form's
BeforeUpdate event. That's what that event is for.

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
Thanks so much for your help. I will do my validation in the Before Updtate
Event.

Regards,
Dan
 

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

Back
Top