PreviousControl Property

Applies To

Screen object.

Description

You can use the PreviousControl property with the Screen object to return a reference to the control that last received the focus.

Setting

The PreviousControl property contains a reference to the control that last had the focus. Once you establish a reference to the control, you can access all the properties and methods of the control.

This property is available only by using a macro or Visual Basic and is read-only.

Remarks

You can't use the PreviousControl property until more than one control on any form has received the focus after a form is opened. Microsoft Access generates an error if you attempt to use this property when only one control on a form has received the focus.

See Also

GotFocus, LostFocus events.

Example

The following example displays a message if the control that last received the focus wasn't the txtFinalEntry text box.

Function ProcessData() As Integer
    Dim ctlPrevious As Control
    ' No previous control error.
    Const conNoPreviousControl = 2483
    On Error GoTo Process_Err
    Set ctlPrevious = Screen.PreviousControl
    If ctlPrevious.Name = "txtFinalEntry" Then
        ' Process Data Here.
            .
            .
            .
        ProcessData = True
    Else
        ' Set focus to txtFinalEntry and display message.
        Me!txtFinalEntry.SetFocus
        MsgBox "Please enter a value here."
        ProcessData = False
    End If
Process_Bye:
    Exit Function
Process_Err:
    If Err = conNoPreviousControl Then
        Me!txtFinalEntry.SetFocus
        MsgBox "Please enter a value to process."
        ProcessData = False
    End If
    Resume Process_Bye
End Function