Using Events

Events are some of the most useful things you can use to control a user interface. Events happen at the form level and at the individual control level. At the form and control levels, there are some key events I find very useful, which I outline here.

OnCurrent

The OnCurrent event runs each time the focus moves between records. There are several reasons to use this. First, based on values in a record, you might want to enable certain buttons and disable others. You can control this by setting the Enabled property of the command buttons based on If...Then statements or Select...Case statements. You might also want to perform some type of calculation or pull some data from another table based on what is in a current record. All of this can be done automatically using the OnCurrent event.

BeforeUpdate/AfterUpdate

The BeforeUpdate and AfterUpdate events are best used on text boxes, combo boxes, etc. The main difference between them is that BeforeUpdate fires prior to making the change to the field, and AfterUpdate fires after the change has been made to the field. Use BeforeUpdate when performing data validation. If the data is not what you expected, take actions to ensure proper data. Depending on what you are trying to do, you might want to test both to make sure that you use the correct one. If you use these events on a control connected to data (and the name of the field is different from the name of the control), when the BeforeUpdate event fires, the text box holds ...

Get Integrating Excel and Access now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.