Current Event — Event Procedures

Description

To create an event procedure that runs when the Current event occurs, set the OnCurrent property to [Event Procedure], and click the Build button.

Syntax

Private Sub Form_Current( )

Remarks

You can't cancel this event by using the CancelEvent method of the DoCmd object. However, you can use the GoToRecord method of the DoCmd object to move to a different record.

See Also   Current event — macros.

Example

In the following example, a Current event procedure checks the status of an option button called Discontinued. If the button is selected, the example sets the background color of the ProductName field to red to indicate that the product has been discontinued.

To try the example, add the following event procedure to a form that contains an option called Discontinued and a text box called ProductName.

Private Sub Form_Current()
    If Me!Discontinued Then
        Me!ProductName.BackColor = 255
    EndIf
End Sub
The next example sets a form's Caption property to the SupplierName field. As the focus moves from record to record, the title bar displays the current supplier name.

To try the example, add the following event procedure to a form that contains a text box called SupplierName.

Private Sub Form_Current()
    Me.Caption = Me!SupplierName
End Sub