HandsOn Writing the Form Dirty Event Procedure

1. Use the Form Wizard to create a new form based on the Northwind database Categories table. Add all the fields as listed in the Categories table and use the Columnar option in the New Form dialog box. Type Product Categories for the form's title and click Finish.

2. Access opens the Product Categories form in Form view. Choose View | Design View and click the Properties button to activate the Form properties sheet.

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

Part IV

4. Access opens the Visual Basic Editor window and writes the stub of the Form_Dirty event procedure. Complete the code of the Form_Dirty event procedure as shown below.

Private Sub Form_Dirty(Cancel As Integer) If CategoryID <= 4 Then

MsgBox "You cannot make changes in this record." Cancel = True End If End Sub

5. Open the Product Categories form in Form view. Try to make any changes to the original records. You will not be able to make changes to the data if the product's CategoryID is less than or equal to 4.

0 0

Post a comment