|Access Developer Reference|
You can use the CodeContextObject property to determine the object in which a macro or Visual Basic code is executing. Read-only Object.
expression A variable that represents an Application object.
The CodeContextObject property is set by Microsoft Access and is read-only in all views.
The ActiveControl, ActiveDatasheet , ActiveForm , and ActiveReport properties of the Screen object always return the object that currently has the focus. The object with the focus may or may not be the object where a macro or Visual Basic code is currently running, for example, when Visual Basic code runs in the Timer event on a hidden form.
In the following example the CodeContextObject property is used in a function to identify the name of the object in which an error occurred. The object name is then used in the message box title as well as in the body of the error message. The Error statement is used in the command button's click event to generate the error for this example.
|Visual Basic for Applications|