Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get the name of the button clicked on a form

Status
Not open for further replies.

addy

Technical User
May 18, 2001
743
GB
Is there anyway of capturing the name of the button just clicked in its OnClick event?

Obviously I know the name and so could 'hard code' it in, but I'd like to call a particular function from many different buttons within my app and I need to pass the name of the control used to that Function.

So rather than having to specify the relevant name each time I was hoping I could just capture the name as a variable and send that to the function.

Thanks.
 

Why don't you just pass a button to that function as a parameter?
Code:
Private Function Something(ByRef btnMyButton As CommandButton) As String

MsgBox "You Clicked " & btnMyButton.Caption

End Function
You just need to figure out what to put in the place of [tt] As CommandButton[/tt]. This is VB 6 syntax, VBA has something like [tt]As UserForm.CommandButton[/tt]

Have fun.

---- Andy
 
Got it thanks - Me.ActiveControl.Name

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top