Hi Alexandr,
couple errors I noticed in the example - not sure if they also apply to your app; I think maybe they're just small errors in making the example, I'm guessing your app is ok though.
a) your use of direction# is broken, because implicit variables only live "inside" one routine, and you're setting it in one routine, but using it in another. Rather make a local variable and then you can set it and use it as you have done.
b) I got an ASSERT when I ran the program because you were using records(MailBoxes) but the MailBoxes table was not opened at that point.
Back to your question - I'm gonna answer this as more of a tutorial than a straight-out answer.
a) you need 7.17 or later
b) put your code in a routine
c) figure out what "events" should trigger the routine [note 1]
d) right-click on the procedure, choose Source, search for TakeEvent Routine and make calls to your routine there.
[note 1] To "see" events as they arrive in the browse in Debugview, turn on the option Send Stage to Debugview.
Cheers
Bruce