Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On Error Event Not Triggering

Status
Not open for further replies.

MelissaT

Programmer
May 16, 2002
67
US
I have read thru some of the other responses to questions like this one, but have not found anyone having this problem. I have some fields that I wish to be required. I have set the required property to yes in the table. On my form, I have but an On Error event procedure, so that when a user tries to close the form, it triggers and then has some code to determine which fields have been left empty and prints an appropriate message.
Example:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Response = acDataErrContinue

If DataErr = 3314 Then
If IsNull(Name) Then
MsgBox "You must provide a name."
Name.SetFocus
ElseIf IsNull(dob) Then
MsgBox "You must provide a date of birth."
dob.setfocus
end if
end if

Here is the problem. The On Error event only triggers if I
1) try to go to the next or previous record. or
2) use the "x" in the upper right-hand corner to close the form.

If I use my button to go back to the Main Menu, the form simply closes with no message and without saving the record.

I am using Access 2000.
Any ideas?

Melissa
Designing Access databases since 1999
 
Add the code to check the name and dob to the command button to close the form, and also add an "Exit Sub" to prevent the closure

Private Sub cmdClose_Click()
If IsNull(Name) Then
MsgBox "You must provide a name."
Name.SetFocus
Exit Sub
ElseIf IsNull(dob) Then
MsgBox "You must provide a date of birth."
dob.setfocus
Exit Sub
End if
DoCmd.Close acForm, "FormName"
End Sub

PaulF
 
Hi!

This is a "known flaw", check out the "flaws" here's a link to Allen Browne's description Losing data when you close a form where you can check out his tip on usage of the dirty property, or forcing a save when closing the form.

Roy-Vidar
 
Thank you for the quick responses. I will add the code behind my button instead and take a look at those other properties. Why is it that everytime I find a really cool feature in access it's always, "flawed"? Awe well, just another day spent trying to figure out what I was doing wrong, only to find out it never worked right in the first place!

Thank you!

Melissa
Designing Access databases since 1999
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top