130 likes | 235 Views
Chapter 2. Intro to VBA Events. Where to plug in your programs?. Click . A common event for buttons and other controls. Use Properties Sheet of the control to provide your own VBA logic for the Click event
E N D
Chapter 2. Intro to VBA Events Where to plug in your programs? MIS333k(Poynor)
Click A common event for buttons and other controls. • Use Properties Sheet of the control to provide your own VBA logic for the Click event • How? Find the “On Click” property and click its builder button to create or edit the VBA code. MIS333k(Poynor)
Form Events These are the common form events. • Open Þ Load Þ Resize Þ Activate Þ Current • Unload Þ Deactivate Þ Close MIS333k(Poynor)
Events you can Cancel To prevent forms opening or closing, and prevent dirty data • Private Sub Form_Open (Cancel As Integer) • Private Sub Form_Unload (Cancel As Integer) • Private Sub Form_BeforeUpdate (Cancel As Integer) MIS333k(Poynor)
Verify user should open this form Cancel efficiently (Cancel = True) Form_Open When to use this event? MIS333k(Poynor)
Form_UnLoad When to use this event? • Close button on form is clicked • To initiate logic that checks whether to close the form • If not closing issue an error message and Cancel the event MIS333k(Poynor)
Form_BeforeUpdate When to use this event? • To inspect controls or fields for valid data (and cancel the update in case of invalid data) • To initiate error messages • To prompt for corrections to fields MIS333k(Poynor)
Form_Current When to use this event? • To coordinate all controls on forms with changes to the record position. Remember the navigation Combo ? • To control smart navigation buttons • Not to check for errors MIS333k(Poynor)
Inside the Form When you move the focus to an existing record on a form, enter or change data in the record, and then move the focus to another record, the following sequence of events occurs for the form: • Current Þ BeforeUpdate Þ AfterUpdate Þ Current MIS333k(Poynor)
Inside a Control • When you change the text in a text box or in a combo box, the Change event occurs. But it occurs before you move to a different control or record (before the BeforeUpdate and AfterUpdate events occur). The following sequence of events occurs for each key you press in a text box or in the text box portion of a combo box: • KeyDown Þ KeyPress Þ Change Þ KeyUp MIS333k(Poynor)
Click • The Click event applies only to forms, form sections, and controls on a form • This event doesn't apply to check boxes, option buttons, or toggle buttons in an option group. It applies only to the option group itself. • MouseDown Þ MouseUp Þ Click Þ DblClick Þ Click MIS333k(Poynor)
Help? • Look for “Event properties reference” • In Help: Index • In Help: Answer Wizard MIS333k(Poynor)