Error "Can't set focus"

If I'm understanding you, I need a call to a sub / function that in turn calls the afterupdate event.

No, obviously my description got a little hazy. I do that sometimes.

What I was suggesting is the other way around. If you are going to call ANY event code from at least two places (once naturally as the result of a proper event, once by explicitly calling the event code from some OTHER event), then whatever you are doing in that case should NOT be in EITHER event routine.

Build a routine that does the thing you wanted to do in common from the (at least 2) different sources and call THAT routine from the legit events. The obvious confusion in doing it that way is that you are still executing the same instructions; you just moved them around, didn't you? (Yes, you did.) But this is done to avoid what are called "side effects."

By forcing those common instructions into a separate common place, you will also be forced to keep track of them and to divide them into smaller, easier-to-debug pieces. You will also get pinged by the compiler if you are doing something that gets visibility problems (visibility of variables, also called "scope"). This is also avoiding an "out of sight, out of mind" case associated with having stuff in-line with legit event-code execution. The other side of this is that you might find a better place to handle that specific action than the AFTER_UPDATE event. The issue is that doing ANYTHING with the potential to "dirty" a form while you are in an AFTER_UPDATE event is - to my mind - very dangerous due to the potential for event loops. Think of it this way. If you call an event routine directly AND that code could also be called by its own proper event, then you are very likely executing that code multiple times in a single record based on events being automatically fired based on form conditions and actions. Will your code do the right thing in a multi-fire environment?
 
+1 for modularization and separation of code. Don't put the "guts" of the code in both an Event stub and another procedure. Rather, put the Guts of the code in only one place...a separate Funtion or Procedure....then call it whenever necessary.
 

Users who are viewing this thread

Back
Top Bottom