HandsOn Writing the FormOnConnect Event Procedure

1. In the Database window, select the Sales Analysis Subform 1 and click the Design button. This is one of the forms included with the Northwind sample database.

2. Choose Edit | Select Form.

3. Choose View | Properties to activate the Form properties sheet.

4. Click the Event tab, set the On Connect property to [Event Procedure], and press the Build button (...).

5. Access will create the event procedure stub. Enter the following Form_OnConnect event procedure:

Private Sub Form_OnConnect()

MsgBox "You have successfully connected to the data source." & vbCrLf _

& "The following SELECT statement will be used for the PivotTable: " _ & vbCrLf & Me.RecordSource

End Sub

6. Switch to the Sales Analysis Subform 1 form and close it. Click Yes when asked to save the design changes.

7. In the Database window, double-click the Sales Analysis Subform 1 form. The Form_OnConnect event procedure will run and you should see the message as coded in step 5 above. Click OK to the message to open the form.

0 0

Post a comment