Passing a button as a parameter

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Can anyone tell me how I pass the button I have just clicked into function
that the OnClick event calls?

My Button calls a function with this setup:

"Function ButtonClicked(MyForm As Form, MyButton As CommandButton)..."

The button's Onclick event is "=ButtonClicked([Form],[CommandButton])"

[Form] passes in the current Form, which is what I want, and why I was
hoping [CommandButton] would pass in the current button, but it doesn't!

Can anyone shed light on where I'm going wrong?

Thanks very much,

Mike
 
mkj said:
Can anyone tell me how I pass the button I have just clicked into function
that the OnClick event calls?

My Button calls a function with this setup:

"Function ButtonClicked(MyForm As Form, MyButton As CommandButton)..."

The button's Onclick event is "=ButtonClicked([Form],[CommandButton])"

[Form] passes in the current Form, which is what I want, and why I was
hoping [CommandButton] would pass in the current button, but it doesn't!


Either use the name of the button is the event property:

=ButtonClicked([Form],[name of button])

Or, don't use a MyButton argument at all:

=ButtonClicked([Form])

Function ButtonClicked(MyForm As Form)
Dim MyButton As CommandButton
Set MyButton = MyForm.ActiveControl
. . .
 
Hi,

That second option is a way of going about it that I hadn't thought of, but
is exactly what I'm after - thanks very much!

Mike

Marshall Barton said:
mkj said:
Can anyone tell me how I pass the button I have just clicked into function
that the OnClick event calls?

My Button calls a function with this setup:

"Function ButtonClicked(MyForm As Form, MyButton As CommandButton)..."

The button's Onclick event is "=ButtonClicked([Form],[CommandButton])"

[Form] passes in the current Form, which is what I want, and why I was
hoping [CommandButton] would pass in the current button, but it doesn't!


Either use the name of the button is the event property:

=ButtonClicked([Form],[name of button])

Or, don't use a MyButton argument at all:

=ButtonClicked([Form])

Function ButtonClicked(MyForm As Form)
Dim MyButton As CommandButton
Set MyButton = MyForm.ActiveControl
. . .
 
Back
Top