When a user acts on the form’s controls, as when selecting an item in a listbox or clicking a button, the appropriate functions in the form's script run. Functions also run for other reasons (as when the form loads or because of events fired by other objects). Each script can contain many subroutines or functions.
Scripts by themselves run and then exit immediately. They do not wait for events, so event handlers only apply in the context of forms. If you want a particular subroutine to run in response to an event, you must include the appropriate script code as part of a form. Once invoked, forms remain open (and running) until you switch to edit mode or close the form.