Passing a button as a parameter

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
 
M

Marshall Barton

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
. . .
 
G

Guest

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
. . .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top