How to reference a button that calls a macro?

coolcps

Registered User.
Local time
Today, 18:58
Joined
May 28, 2009
Messages
22
I have a macro that opens a form. The macro then sets a value in that form. I would like for that value to be the caption value of the button pressed.

Forms![frm_Menu]![button].Caption

I want to know what I need to put in that button field to have it reference the button that the macro is being called from, so I can use this same macro on many buttons and it just inserts the caption as that value. Thanks for any help.
 
Build a general module (if you haven't already). In the data declaration area of the general module, add a line, Public ButtonName as String.

Now in each button's OnClick routine, have it put its own .Caption in the public variable ButtonName.

From there, you can determine which button was used to call the code.

Doing it "backwards" (i.e. trying after-the-fact to trace back what button was pushed) might or might not be possible because macros are clunky technology from a much earlier era. They might not support a call-frame concept quite as well. But if you just store the name BEFORE you activate the macro, you are good to go.

By the way, if the code DIRECTLY activates the macro, change it so that the button wizard gets involved enough to run some triggering code. Then you can add the lines you want to add and still run the macro. There IS a button wizard option for a button to run a macro.
 
I ended up not doing this in the database I wanted it for, but I am trying
to figure it out for future uses.

Now in each button's OnClick routine, have it put its own .Caption in the public variable ButtonName.

I am confused on how to reference the button that the current macro is being called from. How exactly do I have it put its own .Caption into the variable. Thanks.
 
The macro then sets a value in that form.

What is the "value" is it fixed or variable?

I would like for that value to be the caption value of the button pressed.

Have a look at my attached sample it should give you an idea how to make it work.

With my sample you can click it every couple of second and you will see that it updates.
 

Attachments

What is the "value" is it fixed or variable?



Have a look at my attached sample it should give you an idea how to make it work.

With my sample you can click it every couple of second and you will see that it updates.

Let me try to explain this better. Lets say that I have 20 buttons. The caption on each button will be put as a filter in a query. Each of these buttons opens up the same form based on a query. I want to have one macro that I can assign to each buttons on click event, and have it take that individuals caption and insert it as the value for the filter.

I could go make a macro for each button, but I am just trying to figure this out as to streamline this process and save time.

I need a macro or code to pull the caption of the current button being clicked, without naming that specific button anywhere in the code. Thanks for the help so far.
 

Users who are viewing this thread

Back
Top Bottom