Y
Yarik
Hi.
I have a control named (for example, text box named "txtDate") on a
form. Let's say that I want to do something conditionally - only when
this control has focus. I expected the following code to work:
Dim frm as Form
Dim ctl as Control
...
Set ctl = frm.txtDate
...
If (frm.ActiveControl Is ctl) Then
...
EndIf
but it does not: even when the given control is active, operator "Is"
returns false.
One workaround is obvious - instead of using operator "Is" to compare
control references, compare names of controls:
If (frm.ActiveControl.Name = ctl.Name) Then
...
EndIf
However, I am really curious why operator "Is" does not work in this
case? Is it a bug or is it by design?
I am also wondering if there are any other workarounds (in particular,
workarounds that would not rely on uniqueness of control names in a
form)?
Any feedback would be greatly appreciated.
Thank you,
Yarik.
I have a control named (for example, text box named "txtDate") on a
form. Let's say that I want to do something conditionally - only when
this control has focus. I expected the following code to work:
Dim frm as Form
Dim ctl as Control
...
Set ctl = frm.txtDate
...
If (frm.ActiveControl Is ctl) Then
...
EndIf
but it does not: even when the given control is active, operator "Is"
returns false.
One workaround is obvious - instead of using operator "Is" to compare
control references, compare names of controls:
If (frm.ActiveControl.Name = ctl.Name) Then
...
EndIf
However, I am really curious why operator "Is" does not work in this
case? Is it a bug or is it by design?
I am also wondering if there are any other workarounds (in particular,
workarounds that would not rely on uniqueness of control names in a
form)?
Any feedback would be greatly appreciated.
Thank you,
Yarik.