Error trapping for custom message unsuccessful

Archie999

Access Wannabee
Local time
Yesterday, 17:31
Joined
May 25, 2003
Messages
45
Hi All,

For some reason the following code is not trapped when I get the error message (3201) 'The field 'whatever' cannot contain a Null vaue because the Required property for this field is set to True. Enter a value in this field.'

This is my code and it actually works fine in a different form but here it does not. I added a message box to show me the err. number before going to the code below and the response I got was '0'. Not sure why. Does anyone see a problem.

Thanks

If DataErr = 3201 Then

If vbYes = MsgBox("You cannot exit the form yet. You must complete the form or cancel out of it." _
& vbNewLine & "Do you want to cancel and delete the record you are currently adding?", _
vbYesNo + vbQuestion, "Delete Record") Then

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
Response = acDataErrContinue

Else
Response = acDataErrContinue
End If
End If
 
Archie999 said:
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

Can we assume this code is in the form's OnError event?
What line does the code stop at?

And by the way, the line of code I quoted above is obsolete.
Anything with DoCmd.DoMenuItem is obsolete. You should now use DoCmd.RunCommand.
 
Yes, the code is in the form's error event. That part is definetly working because when I put a MsgBox(err.Number) before the IF statement, that part runs and returns a value of 0 in the Message Box. So, when I think of it, the code is likely fine (albiet obsolete in parts). The question is why isn't there a valid error code associated with my error message?

Any ideas??

Thanks much!

Arch
 
I would suggest using the forms BeforeUpdate event to test if the user is trying to save a record that does not meet your conditions. That would be triggered if the user tries to move to another record , if the user tries to close the form or close the application.
 

Users who are viewing this thread

Back
Top Bottom