HandsOn Writing the Form BeforeInsert Event Procedure

1. Use the Form Wizard to create a new form based on the Northwind Customers table.

2. Select the following fields: Customerld, CompanyName, Address, City, Region, PostalCode, and Country. Step through the Form Wizard screen, pressing the Next button until you get to the screen where you are asked for the form's title. Type New Customers for the form's title and click Finish.

3. Access opens the New Customers form in Form view. Choose View | Design View and click the Properties button to activate the Form properties sheet.

4. In the Form properties sheet, click the Data tab and set the Data Entry property to Yes.

Part IV

5. In the Form properties sheet, click the Event tab. Click next to the Before Insert event property and choose [Event Procedure] from the drop-down box. Click the Build button (...).

6. Access opens the Visual Basic Editor window and writes the stub of the Form_BeforeInsert event procedure. Complete the code of the Form_ BeforeInsert event procedure as shown below.

Private Sub Form_BeforeInsert(Cancel As Integer)

Me.Country = "USA" End Sub

7. Switch to the New Customers form currently open in the Design view.

8. Choose View | Form View. As soon as you start filling in the form's text boxes, the text "USA" appears in the Country field.

9. Close the New Customers form without saving it.

0 0

Post a comment