Thread: [Solved] Find textbox name
View Single Post
 
Old 01-31-2014, 03:11 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Hdata View Post
I created a command button on the userform and attached the code below:

Code:
Private Sub cmdTextBoxName_Enter()
MsgBox Me.ActiveControl.Name
End Sub
What I received back was
"cmdTextBoxName"

The name of the textbox is actually "Document_City"
What am I missing?
Well, your sub's name (cmdTextBoxName_Enter) shows that the control's name can only be 'cmdTextBoxName'. Evidently, you want something else; perhaps the name of a visually-related label. If so, unless the label and control are grouped (and nothing else is in the same group), there is no 100% reliable way for VBA to identify which one you want.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote