Current Event, Close Event, Undo Event in Access


Current Event Visual Basic Example

The form VBA Current event (or On Current event) activates when the focus moves to a record on the form. This action makes this record the ‘current record’.  This event also occurs after a form is opened, requeried or refreshed.

Current Event Example:

In this example we change the field Due_Date to red when the value of this field is less than today’s date and the field Completed=false.

Private Sub Form_Current()
If Me!Due_Date < Date and Me!Completed=False Then
Me!Due_Date.BackColor = 255
Me!Due_Date.BackColor = vbWhite
End If
End Sub

The event sequence for the Current Event is:

Open → Load → Resize → Activate → Current

Close Event Visual Basic Example

Visual Basic On Close event occurs when a form is closed and removed from the screen.

On Close Event Example:

This is a subroutine we use often on the main menu of an Access database to prevent the user from attempting to get into the database objects.  In this example Microsoft Access will exit if the user closes the form.

Private Sub Form_Close()
End Sub

The event sequence when closing a form is as follows:

Unload → Deactivate → Close

VBA Undo Event Example

Visual Basic Undo event happens when the user undoes a change to a combo box control, a form, or a text box control.(adsbygoogle = window.adsbygoogle || []).push({});

Undo Event Visual Basic Example:

The following example shows how to trap the undo event on a form.  In this case we will confirm that the user wants to cancel the undo operation.

Private Sub Form_Undo(Cancel As Integer)
If MsgBox(“Do you want to cancel the Undo?”,vbYesNo) = vbYes Then
Cancel = True
Cancel = False
End If
End Sub

Form Triggers
Table Triggers
Form Flags
Table Triggers
Record Flags
Record Events

Microsoft Office:
MS Access 2003
Access 2007
Access 2010
Access 2013
Access 2016


Microsoft Office VBA, MS Access 2003, 2007, 2010, 2013, 2016