HandsOn Writing the Form DataChange Event Procedure

1. In the Visual Basic Editor window, double-click Form_Sales Analysis Subform 1.

2. The Code window shows several event procedures you prepared earlier in this chapter. Enter the following Form_DataChange event procedure below the last procedure code.

Event Programming in Forms and Reports

Private Sub Form_DataChange(ByVal Reason As Long) Select Case Reason

Case OWC11.plDataReasonAllIncludeExcludeChange

Debug.Print "Change in the included/excluded members." Case OWC11.plDataReasonIncludedMembersChange

Debug.Print "Included Members Change" Case OWC11.plDataReasonExcludedMembersChange

Debug.Print "Excluded Members Change" Case Else

Debug.Print "Reason code: " & Reason End Select End Sub

3. To test the above event procedure, open Sales Analysis Subform 1 in Form view. Because you've already created several event procedures for this form, various events will be triggered as the form is being loaded. Respond to all the prompts and, once the form opens, click the drop-down arrow next to the Last Name button and choose to add or remove an employee. Then switch to the Immediate window in the Visual Basic screen to see the captured Reason codes and changes in the included /excluded members.

0 0

Post a comment