Solved StopMacro VS CancelEvent (1 Viewer)

Sarah.M

Member
Local time
Today, 08:33
Joined
Oct 28, 2021
Messages
335
Hi, Plz note, My VBA is blocked by IT for security reason.
I can use only Expression builder, Macros, Queries, Tables, Forms and Reports only.
------------------------------------------------
what is the main deferent between StopMacro and CancelEvent?
Both are going to stop macro so what is the main deferent,
plz give us some example 🙏
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:33
Joined
Oct 29, 2018
Messages
21,471
Hi. Not all events can be canceled. So, you can't use CancelEvent all the time. For example the Open and Close events. One can be canceled, the other one cannot.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:33
Joined
Feb 19, 2002
Messages
43,266
Cancel Event is CRITICAL if you are trying to validate data. If you want to prevent data from being saved, you MUST cancel the BeforeUpdate event. Just stopping the macro won't stop data from being saved if you are in the BeforeUpdate event.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:33
Joined
Feb 28, 2001
Messages
27,179
Hi, Plz note, My VBA is blocked by IT for security reason.
I can use only Expression builder, Macros, Queries, Tables, Forms and Reports only.
------------------------------------------------
what is the main deferent between StopMacro and CancelEvent?
Both are going to stop macro so what is the main deferent,
plz give us some example 🙏

StopMacro prevents FURTHER code / macro execution but whatever you have done so far is done - by you.

Events, on the other hand, are done by Access itself. The "OnEvent" properties point to code or lists of macro steps to do IN ADDITION to the internal Access actions associated with the event in question. Even if you have no actions associated with a particular event, it will still happen. A CancelEvent prevents ACCESS from completing the internal code associated with the event.

So for example, if you have a BeforeUpdate event, the event will run to completion if you don't cancel it (and an update will occur) REGARDLESS of having a STOP MACRO action in the macro associated with the event. By way of contrast, you can also have a CancelEvent that would stop the BeforeUpdate event from letting an update happen - but if you don't have a STOP MACRO in the macro action list, YOUR event code WILL run to completion.
 

Users who are viewing this thread

Top Bottom