Agree that Philipp's contribution was very valuable. Its critical tone certainly made me question some of my earlier comments.
Unfortunately, Microsoft do not appear to have any documentation for exactly what End should do in that error dialog
I had searched for it unsuccessfully.
Nor is it mentioned in various form events documentation that I had looked at including Form_Unload
Lets try and see what we all agree on:
- Clicking End in the error dialog stops code execution immediately
- Up to A2003, Pat's code in Form_Unload closed the form after triggering the error
- From A2007 onwards, the error triggers but the form doesn't close.
- Using error handling avoids any issues
- The behaviour is identical for ACCDB and MDB so its (probably) not changed as a requirement of the new file format
I've done some further tests using exactly the same code in different events.
In each case the error occurs and no code after that runs in that event
- Open event (cancellable) - the form does not open
- Load event - the forms finishes loading and proceeds to the next event (Activate)
- Activate event - completes and moves to next event (Current)
- Current event - completes and moves to next event (Timer)
and then
- Unload (cancellable)- does not proceed to next event (Deactivate)
- Deactivate - completes and moves to next event (Close) or closes if no further event code
- Close - completes and form closes
As the only events that fail to 'complete' are those that can be cancelled, this may be the clue to the behaviour.
But the code supplied by
@Pat Hartman is not trying to Cancel the event
All this still doesn't confirm whether the changed behavior from almost 20 years ago was deliberate or a bug.
I stated my opinion back in post #10 but maybe I am wrong. Certainly, I wish I had stopped after post #10!
However, to repeat, I had already checked the documentation for Form_Open & Form_Unload and it does not provide clear information on this behaviour. The only warning is this paragraph in the
Form_Unload Event page
Note
When you create macros or event procedures for events related to the Unload event, such as Deactivate and LostFocus, be sure that they don't conflict (for example, make sure that you don't cause something to happen in one macro or procedure that is canceled in another) and that they don't cause cascading events.
Either way, the behaviour is certainly undesirable (as Josef P. said above) and re-emphasises the need for error handling
I would have no personal objection if the original behaviour was restored. It has never bitten me in all the years I've been using Access.
I doubt very much backward compatibility would be cited as an issue as I suspect this has hardly ever arisen in almost 20 years.
In her sample db to the A-team Pat has asked whether this behaviour is intentional:
The database contains two forms. One with an error trap is suffixed _AllowClose, the other is suffixed _CannotClose.
I think in the _CannotClose version, the End button on the Access error message should gracefully close the form. Instead, it leaves the form open, which is what I think Contunue should do, except that Continue is greyed out. Because End does not close the form, the user is forced to use Task Manager to close Access.
If you disagree regarding the operation of the End button, then please explain the difference between Continue and End.
Hopefully Shane from the A-team will clarify the behaviour including the purpose of each button and we can all move on!