HandsOn Using the Before Update Event Procedure for the Combo Box Control

1. Make sure that the frmDataEntryMain form is open in Design view.

2. Right-click the list box control to the right of the Site ID label and choose Build Event from the shortcut menu.

3. The Microsoft Visual Basic Editor window will appear with the cursor positioned inside the following event procedure:

Event Programming in Forms and Reports

Private Sub cboSiteId_BeforeUpdate(Cancel As Integer) Dim strMsg As String, strTitle As String Dim intStyle As Integer

If IsNull(Me!cboSiteId) Or Me!cboSiteId = "" Then strMsg = "You must pick a value from the Site ID list." strTitle = "Site ID Required" intStyle = vbOKOnly MsgBox strMsg, intStyle, strTitle Cancel = True End If End Sub

4. Position the cursor inside the If statement, then press F9 or choose Debug | Toggle Breakpoint.

5. Activate the frmDataEntryMain form in Form view and make a selection from the Site ID combo box.

When you make your selection, the BeforeUpdate event procedure is fired and the Code window appears in Break mode. Press F8 to step through the code line by line. Because you have not set up more breakpoints, you cannot see that two other events (cboSiteId_AfterUpdate and cboRooms_ Enter) were triggered when you made a selection from the Site ID combo box.

6. When the procedure finishes executing, activate the frmDataEntryMain form. You should see the text boxes filled with a school name and address and the cursor positioned inside the Room No combo box and ready for the next selection or data entry.

0 0

Post a comment