Unload event

P

Pietro

Hi,

I want to write a code in the Unload event of a form that prevents the
form from being closed if the field [escalated by] is null...
 
D

Douglas J. Steele

Private Sub Form_Unload(Cancel As Integer)

Cancel = IsNull(Me![escalated by])

End Sub
 
P

Pietro

Well,
Thank you so much Douglas,but the I've two concerns on the below code:
1-It displays a message 'no current record',i want it to be "You cannot eit
without filling the mandatory data"
2-When i click the button 'next' or 'back' i can escape the code and moce to
another record that has the field [escalated by] not null,so users can exit
the page,is there a way to prevent users not only from closing the page but
also from moving to another record?

Douglas J. Steele said:
Private Sub Form_Unload(Cancel As Integer)

Cancel = IsNull(Me![escalated by])

End Sub

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Pietro said:
Hi,

I want to write a code in the Unload event of a form that prevents the
form from being closed if the field [escalated by] is null...
 
D

Douglas J. Steele

Yeah, I forgot to check whether or not there actually was a dirty record.

Private Sub Form_Unload(Cancel As Integer)

If Me.Dirty Then
Cancel = IsNull(Me![escalated by])
End If

End Sub

As to being able to move to another record, if it's not valid that a record
be saved with that field being Null, you need to trap that in the form's
BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull(Me![escalated by] Then
MsgBox "You must enter who escalated it"
Cancel = True
End If

End Sub

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Pietro said:
Well,
Thank you so much Douglas,but the I've two concerns on the below code:
1-It displays a message 'no current record',i want it to be "You cannot
eit
without filling the mandatory data"
2-When i click the button 'next' or 'back' i can escape the code and moce
to
another record that has the field [escalated by] not null,so users can
exit
the page,is there a way to prevent users not only from closing the page
but
also from moving to another record?

Douglas J. Steele said:
Private Sub Form_Unload(Cancel As Integer)

Cancel = IsNull(Me![escalated by])

End Sub

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Pietro said:
Hi,

I want to write a code in the Unload event of a form that prevents
the
form from being closed if the field [escalated by] is null...
 

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