cancel form unload

L

Lloyd

I am doing some data verification in my subform, but users are able to get
around this by just selecting the X and closing the form while in the field.
Is there a way in the fields on exit event, that when the code runs telling
the user they must enter the required data that it also stops the form from
unloading? Otherwise I assume my only option is to put the same code in the
forms unload event, is that correct?

sample code below:

Private Sub Method_Exit(Cancel As Integer)

If Me.PersonCaseType Like "Mur*" And Me.PersonType = "Victim" Then

If IsNull(Me.Method) Then
MsgBox "You must enter a Method of Attack for this person", vbCritical,
"Enter a Method of Attack"
Cancel = True

End If
end sub
 
L

Linq Adams via AccessMonster.com

Checking for null fields cannot be done reliably in any event of the control
itself. This kind of validation needs to be done in the Form_BeforeUpdate
event. It will then be executed whether moving to another record or closing
the foem.
 

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