Table of contents
Collapse the table of content
Expand the table of content

Screen.PreviousControl Property (Access)

office 365 dev account|Last Updated: 6/12/2017
1 Contributor

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


expression. PreviousControl

expression A variable that represents a Screen object.


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.

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.


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

Public Function ProcessData() As Integer 

 ' No previous control error. 
 Const conNoPreviousControl = 2483 
 Dim ctlPrevious As Control 

 On Error GoTo Process_Err 

 Set ctlPrevious = Screen.PreviousControl 
 If ctlPrevious.Name = "txtFinalEntry" Then 
 ' Process Data Here. 
 ProcessData = True 
 ' Set focus to txtFinalEntry and display message. 
 MsgBox "Please enter a value here." 
 ProcessData = False 
 End If 

 Set ctlPrevious = Nothing 
 Exit Function 

 If Err = conNoPreviousControl Then 
 MsgBox "Please enter a value to process.", vbInformation 
 ProcessData = False 
 End If 
 Resume Process_Exit 

End Function

See also


Screen Object

© 2018 Microsoft