Returns a reference to the object that invoked the current event.
Read-only property
object.Object |
Object
This property is very useful when working with form objects that respond to events. It allows you to reference other related form objects without using their full paths. For example, the following code lets you easily reference other controls on the same page as the control responding to an event (for example, OnClick for a Button control, OnSelChange for a ComboBox control, and so on). You can also easily reference the control's form:
Dim theControl, allControls, theForm
Set theControl = ThisEvent.Object
Set allControls = theControl.Parent.Controls
Set theForm = theControl.Parent.Parent
You can now easily get or set the values of other controls on the page, as well as the control responding to the event, as in the following example:
Dim value1, value2, value3
value1 = theControl.Value
value2 = allControls("TextBox1").Value
value3 = allControls("ComboBox1").Value
The Object property is the default property for the ThisEvent object. Therefore, the following two lines of code will yield the same result:
Set theControl = ThisEvent.Object
Dim theControl, allControls, theForm
Set theControl = ThisEvent.Object
Set allControls = theControl.Parent.Controls
Set theForm = theControl.Parent.Parent
You can now easily get or set the values of other controls on the page, as well as the control responding to the event, as in the following example:
Dim value1, value2, value3
value1 = theControl.Value
value2 = allControls("TextBox1").Value
value3 = allControls("ComboBox1").Value
The Object property is the default property for the ThisEvent object. Therefore, the following two lines of code will yield the same result:
Set theControl = ThisEvent.Object