You can create a "user defined function (udf) or a procedure. Either of these will work for you. You'll need to create a seperate text file for either or both of these. Then, in your data entry program, call these files like this:
set udf to <filename>
or
set procedure to <filename>
Either one of these set-ups is basically a miniature file or macro that can be called when certain conditions are met.
Good luck! There's always a better way...