Yeah, that works, but it still requires explicitly naming the outer object again. When the outer object is something with several levels deep dot notation, that is a nuisance. Thank you, but I've pretty well resigned myself to "it can't be done".This was as close as I could get. It will get a red fred.
Code:Option Compare Database Option Explicit Private Sub cmdAction_Click() With LabelB .Caption = "Fred" Call SetColor(Me.LabelB) End With End Sub Function SetColor(ctl As Control) ctl.BackColor = vbRed End Function
I didn't notice any attempts to help - only snarky comments about pseudo-code and being specific, along with something that sounded like a knee-jerk reaction, rather than a response to what I actually wrote. And being on your ignore list suits me just fine - you have nothing useful to say either.
@pdanes
I believe I have helped you before now but your responses in this thread have alienated several experienced forum members including myself.
Next time you post, you will get far fewer replies.
You have, and I am grateful for that. I have also helped others, here and in many other forums. But I try to help, not post useless criticisms. These two did not - they were insulting and condescending, and I have no use for that, on a forum or in person.
Second try. It does allow an implicit call value. Fred is red.
Code:Option Compare Database Option Explicit Private Sub cmdAction_Click() With LabelB .Caption = "Fred" Call SetColor(.Name) End With End Sub Function SetColor(arg As String) Dim ctl As Control For Each ctl In Me.Controls If ctl.Name = arg Then ctl.BackColor = vbRed Exit For End If Next End Function
Hm, yes. Thank you, that's a good trick. It's still not a direct reference to the object itself, but using the Name property allows the syntax I was striving for.Second try. It does allow an implicit call value. Fred is red.
Code:Option Compare Database Option Explicit Private Sub cmdAction_Click() With LabelB .Caption = "Fred" Call SetColor(.Name) End With End Sub Function SetColor(arg As String) Dim ctl As Control For Each ctl In Me.Controls If ctl.Name = arg Then ctl.BackColor = vbRed Exit For End If Next End Function
The sub needs to be coded to pick up the name, as you have done in your example, and the object must have a Name property, but most of the things I work with have that, and changing the sub to use the Name property is trivial. It's far better than repeating the entire initial reference.
Many thanks, I'll put that in place wherever I can.
Glad I could help. Nice puzzle to work on. Good luck with the project.Hm, yes. Thank you, that's a good trick. It's still not a direct reference to the object itself, but using the Name property allows the syntax I was striving for.
The sub needs to be coded to pick up the name, as you have done in your example, and the object must have a Name property, but most of the things I work with have that, and changing the sub to use the Name property is trivial. It's far better than repeating the entire initial reference.
Many thanks, I'll put that in place wherever I can.