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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call one function from multiple form buttons?

Status
Not open for further replies.

Keph

Technical User
Oct 15, 2002
16
0
0
CA
I know it's easy to call an event proceedure from a form button, but I have several buttons and I want them to call the same function (passing it a different argument for each button). I have the function created on the same form as the buttons. I tried entering the name of the function in the properties box for "onclick" but when the button is clicked it says it can't find the specified macro. Is there a way to do what I'm trying to do? Any info would be a big help.

Thanks,
Keph
 
Hi Keph!

You can put the call command in the event procedure of the button clicks. If you want to call a function directly then, in the onclick box on the events tab in the property window type =function(). I am not sure if you can call a function in the same form or not, I have only used this to call public functions from modules. Note, instead of passing a parameter, you can determine the parameter in the function using the ActiveControl property of the Screen object.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Thanks for your help guys! It worked when I put the function in a module.

Keph
 
I agree with other replies that calling a function from different places is consistent with the programming language - e.g. calling a Square Root function or any other at any time. I recommend getting into the code window where all the event procedures are found. Then create your event procedures from here rather than from the Forms property dialogue. To create the procedures select (at top of window) the form element from drop-down list and then select the event from drop-down list just to right of element list. Then in each form element procedure (e.g. cmd1_click()) call the function with the appropriate parameters being passed. All this assumes of course that the Function procedure has been created in this same code window. I would try Private Function first, then Public Function next, then placing the Function on a standard module (vs. form module). One more thought: you mentioned "missing macro" warning - I've had that when I'm in the code window and running a procedure (generally not an event procedure) from there using Run tool bar button - this warning occurs when my cursor is not inside the procedure.
Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top