Y
Yarik
Hello all,
Here is the code that demonstrates an interesting phenomenon (this
code is for a simple form having just 3 controls - a labeled text box
and a command button):
-------------------------------------------8<---------------------------------------
Private Sub Command2_Click()
Dim ctl As control
For Each ctl In Me.Controls
Debug.Print "Control name.............: " & ctl.Name
Debug.Print "Is control itself........: " & (ctl Is
Me.Controls(ctl.Name))
Debug.Print "Control name.............: " &
ctl.Properties("Name")
Debug.Print "Is control still itself..: " & (ctl Is
Me.Controls(ctl.Name))
Debug.Print
Next
End Sub
-------------------------------------------8<---------------------------------------
The output is:
-------------------------------------------8<---------------------------------------
Control name.............: Text0
Is control itself........: True
Control name.............: Text0
Is control still itself..: False
Control name.............: Label1
Is control itself........: True
Control name.............: Label1
Is control still itself..: False
Control name.............: Command2
Is control itself........: True
Control name.............: Command2
Is control still itself..: False
-------------------------------------------8<---------------------------------------
Further experiments suggest that any attempt to access any property of
the control breaks what seems to be an invariant:
ctl Is Me.Controls(ctl.Name)
Unfortunately, I cannot find any hints (let alone explanations) of
such behavior in Microsoft's documentation. Is this a feature or a
bug? Did anybody encounter this problem and, ideally, any workaround?
Thank you,
Yarik.
P.S. I know that expression "ctl.Name" is not very good, because
"Name" is not an "official" property of Access.Control object.
Probably it is better to use the following expression instead:
ctl.Properties("Name")
But this does not change the essence of the problem. In fact, in the
light of the abovementioned problem with properties, it actually seems
to be dangerous to obtain control's name via its Properties
collection. :-(
Here is the code that demonstrates an interesting phenomenon (this
code is for a simple form having just 3 controls - a labeled text box
and a command button):
-------------------------------------------8<---------------------------------------
Private Sub Command2_Click()
Dim ctl As control
For Each ctl In Me.Controls
Debug.Print "Control name.............: " & ctl.Name
Debug.Print "Is control itself........: " & (ctl Is
Me.Controls(ctl.Name))
Debug.Print "Control name.............: " &
ctl.Properties("Name")
Debug.Print "Is control still itself..: " & (ctl Is
Me.Controls(ctl.Name))
Debug.Print
Next
End Sub
-------------------------------------------8<---------------------------------------
The output is:
-------------------------------------------8<---------------------------------------
Control name.............: Text0
Is control itself........: True
Control name.............: Text0
Is control still itself..: False
Control name.............: Label1
Is control itself........: True
Control name.............: Label1
Is control still itself..: False
Control name.............: Command2
Is control itself........: True
Control name.............: Command2
Is control still itself..: False
-------------------------------------------8<---------------------------------------
Further experiments suggest that any attempt to access any property of
the control breaks what seems to be an invariant:
ctl Is Me.Controls(ctl.Name)
Unfortunately, I cannot find any hints (let alone explanations) of
such behavior in Microsoft's documentation. Is this a feature or a
bug? Did anybody encounter this problem and, ideally, any workaround?
Thank you,
Yarik.
P.S. I know that expression "ctl.Name" is not very good, because
"Name" is not an "official" property of Access.Control object.
Probably it is better to use the following expression instead:
ctl.Properties("Name")
But this does not change the essence of the problem. In fact, in the
light of the abovementioned problem with properties, it actually seems
to be dangerous to obtain control's name via its Properties
collection. :-(