HandsOn Writing the Form Current Event Procedure

1. Open the Acc2003_Chap24.mdb file from the book's downloadable files or, if you'd like to start from scratch, create a new Microsoft Office Access database. This database should contain tables, queries, forms, and reports from the sample Northwind database. You can import these objects by choosing File | Get External Data | Import or you can create a copy of the Northwind database to be used for this chapter's hands-on exercises.

2. In the Database window of the Acc2003_Chap24 database, select the Products form and click the Design button.

3. Choose View | Properties or click the Properties button on the toolbar to display the Form properties sheet.

Event Programming in Forms and Reports

4. Click the Event tab. Click next to the On Current event property and choose [Event Procedure] from the drop-down box. Click the Build button (...).

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

Private Sub Form_Current()

If Discontinued = True Then

Me.Section(1).BackColor = 255 Me.Picture = ""

Else

Me.Picture = "C:\Program Files\" & _ "Microsoft Office\Office11\" & _ "Bitmaps\Styles\Stone.bmp"

End If End Sub

6. To test the above event procedure, activate the Products form that is currently open in the background in the Design view. Choose View | Form View. Use the record selectors to move to record 5. Because this record is marked as Discontinued, the code in the Form_Current event will change the header section's color to red.

0 0

Post a comment