Toolbars to run "OnClick" procedures

G

Guest

I have created a number of buttons on some forms which have some code behind
the "OnClick". I now want to create a toolbar that has buttons to run the
comands. The only way I can see that this can be done is by putting a Macro
behind the Toolbar button, putting a function (Code Module) behind the Macro
and having the Function open the "OnClick" procedures that are already
written. Only problem is I donot know how to write the Function that calls
the "OnClick" procedure! is there an easier way to do this whole thing, or
does anyone know how to write a function that calls the "OnClick" functions?
I am using Access 2003
 
S

Simonglencross

You could simply try using a macro acompanying the onclick function. hope
this helps


Simon
 
G

Guest

Hi Simon,

I have had a look at that option, however the only ones that relate to what
I am trying to achive are the RunComand and RunCode. The RunCode looks for a
global function (i think) and the RunComand looks for a comand. I think im a
little lost! is there a specific type of Macro that launches onclicks?


Winkle
 
A

Albert D. Kallal

The trick to making this work is to declare the function in the form as
PUBLIC.

That way, you can have any code run. So, to have both a button on the form,
and a menu option, or toolbar option in your case, you simply declare a
PUBLIC function in the form that calls the click code.

Lets say you have some button code to print a invoice. You now are cleaning
up your forms..and moving buttons to the tool bar to save space, or make
things more user friendly.

Just declare a PUBLIC function in he form that calls the code for the
button.

Public Function MyInvoicePrint

Call cmdIV_Click

End function

Note that the menu bars etc can ONLY call functions..and your button click
events are "subs".

Anyway, now, in the menu bar, or tool bar, for the "on action" setting you
go:


=MyInvoicePrint()

That is all you need. So, any menu bar, or tool bar can call code. Also, if
you make the function public in a standard module..then that also works.
And, if both a form is loaded, and a pubic function with the same name
exists in the form (with the focus) and a standard code module, then the
forms code is called.

Thus, you can make a global function in a module for all forms, and if the
form has a special case..then put the code in that particular form. This
way, you can even built tool bars that apply to different forms. So, you
could for example make all your forms with a public function called
MyDelete..and then your tool bar will work with all forms to delete
somthing. And, for many of the forms..perahps the delete code is EXACLTY the
same, and thus you don't put in a "myDelete" function in the form..but let
the global one be called..
 

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