Hi,
I have 5 buttons that i only mapped to 1 Procedure. My issue is I need to know the Button name or caption when it is click.
Do anyone know how to do that?
Much appreciated.
Thank you
Lex
Hi,
I have 5 buttons that i only mapped to 1 Procedure. My issue is I need to know the Button name or caption when it is click.
Do anyone know how to do that?
Much appreciated.
Thank you
Lex
Last edited by lexusap; 09-27-2016 at 12:30 AM.
Hi,
The simplest method is to use Me.ActiveControl.Caption in your code, as long as the TakeFocusOnClick property of the buttons is set to True- which is the default.
Don
Please remember to mark your thread 'Solved' when appropriate.
The easiest option is to share your code so we can take a look and give you a to the point answer.
Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.
Maybe:
use the code
Private Sub UserForm_Initialize()
'
CommandButton1.Tag = "CommandButton1"
CommandButton2.Tag = "CommandButton2"
CommandButton3.Tag = "CommandButton3"
CommandButton4.Tag = "CommandButton4"
CommandButton5.Tag = "CommandButton5"
'
End Sub
Private Sub CommandButton1_Click()
'
MsgBox "Caller = " & CommandButton1.Tag
'
End Sub
Private Sub CommandButton2_Click()
'
MsgBox "Caller = " & CommandButton2.Tag
'
End Sub
Private Sub CommandButton3_Click()
'
MsgBox "Caller = " & CommandButton3.Tag
'
End Sub
Private Sub CommandButton4_Click()
'
MsgBox "Caller = " & CommandButton4.Tag
'
End Sub
Private Sub CommandButton5_Click()
'
MsgBox "Caller = " & CommandButton5.Tag
'
End Sub
Hi,
Thanks for your help, however i still could not figure out what how to fix this.
So in plain language, when any of the 4 buttons being clicked, it will call BN50_Send_no_Payment_file.![]()
Sub BN50_Send_no_Payment_email() 'using if functiong 'If "No Payment DKK Button click" then ' Call ABC1 or show caption 'elseIf "No Payment FIN Button click" then ' Call ABC2 or show caption 'elseIf "No Payment SEK Button click" then ' Call ABC3 or show caption 'elseIf "No Payment NOK Button click" then ' Call ABC4 or show caption 'End If End Sub
However depending on which one that has been clicked, i need to configure which file to get & who to send it.
I have attached sample for your consideration.
Thanks
Lex
You can change the called routine to
and the buttons' code to![]()
Sub BN50_Send_no_Payment_email(sCaption As String) Select Case sCaption Case "No Payment DKK" ' Call ABC1 or show caption Case "No Payment FIN" ' Call ABC2 or show caption Case "No Payment SEK" ' Call ABC3 or show caption Case "No Payment NOK" ' Call ABC4 or show caption Case Else End Select End Sub
However I see no real benefit in having all the buttons call one routine simply so that routine can call other routines for each button. Why do you not rather have each button call its related routine directly?![]()
Private Sub CmdBtnDKK_Click() BN50_Send_no_Payment_email CmdBtnDKK.Caption End Sub Private Sub CmdBtnFIN_Click() BN50_Send_no_Payment_email CmdBtnFIN.Caption End Sub Private Sub CmdBtnSEK_Click() BN50_Send_no_Payment_email CmdBtnSEK.Caption End Sub Private Sub CmdBtnNOK_Click() BN50_Send_no_Payment_email CmdBtnNOK.Caption End Sub
Thanks XLNitWit.
It works perfectly.
Regards
Albert
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks