8.1. When Events Fire
Events are at the heart of event-driven programming—which is no surprise. What can be surprising to novice programmers is the sheer number of events available to use. They all beg to have some code behind them. In reality though, very few events are used on a consistent basis. Most of them have absolutely no code behind them, and never will in normal usage. The trick is to know which ones are important and commonly used, and which ones are obscure and hardly ever used. They all look equally important in Access Help.
8.1.1. Common Form Events
To cut to the chase, here's a list of commonly used events and how you might want to use them. If you know how to use this basic set of events, you're most of the way there to understanding event-driven programming in Access VBA.
|On Open||Fires before the On Load event (so you can't reference any bound controls on your form yet because they haven't been instantiated) and before the recordset is evaluated for the form. This means you can use this event to change the recordset (by changing the WHERE or ORDER BY clause) before the form continues to load. Cancel this event by setting its intrinsic parameter Cancel = True, so the form will close without continuing to the On Load event.|
|On Load||Fires after the recordset for the form has been evaluated but before the form is displayed to the user. This offers you an opportunity to make calculations, set defaults, and change visual attributes based on the data ...|