commands

maxmangion

AWF VIP
Local time
Today, 18:11
Joined
Feb 26, 2003
Messages
2,805
Can these three be used interchangeably:

Cancel = True
Me.Undo
DoCmd.CancelEvent

if no, which should be used when ?

Thanks
 
Me.Undo is like CTRL+z it's an undo, you cannot undo a close operation.

When Closing a form, ive noticed the DoCmd.CancelEvent errors, and only for me Cancel = True plain old dosent work.

They are three different things... that all share common aspects though.

Cancel = True *SHOULD* Cancel the block of code you're running.
DoCmd.CancelEvent *SHOULD* Cancel the current operation (like a query that's running or something... could be used to make a cancel button.)
Me.Undo *SHOULD* Undo userinput...
 
Cancel = True
Me.Undo
DoCmd.CancelEvent

Not at all interchangeable.

Cancel=True ONLY works when the event code where you try to use it supports cancellation. For instance, you cannot cancel a GotFocus event. You can tell because if you allow the wizard to build the event code shell, it will include an argument named Cancel in the formal argument list.

DoCmd.CancelEvent is one I never use, but I suppose you could use it to cancel an event of some sort. I would read and re-read the help files on this one a LOT before using it in preference to the other items you named.

Me.Undo is the moral equivalent of starting a BEGIN TRANSACTION but then doing a CANCEL rather than a COMMIT. I use it on forms a lot, less in other places. Particularly since the ME syntax is usually a form. (Theoretically, also a report, but that would not legally have anything to undo.)

Me.Undo is not necessarily event-based, either.
 
DoCmd.CancelEvent is one I never use
- Me neither. I'm guessing that it's a hold over from the early days. Cancel = True is the preferred method and it only works in events that can be cancelled. DoCmd.CancelEvent will also work in events that can be cancelled but NOT in others. That's why you get an error if you use this in the Close event.That event cannot be cancelled. You need to cancel the Unload event if you want to stop a form from closing.
 

Users who are viewing this thread

Back
Top Bottom