How to assign function to CommandBarButton ?

  • Thread starter Thread starter Albert
  • Start date Start date
A

Albert

Hello all Experts,

Many of my forms contain the same public function name, say abc(), and
purpose is to be assigned to On Action of a specific CommandBarButton of
each Form's CommandBar. Do I have to write any prefix to abc() , such as
Form1.abc() , to let Access know this abc() is of Form1. Actually, I have
tried, But Access can not recognize this format (Form1.abc()).

Regards,
Albert
 
Albert,

Put abc() in a standard module under the Modules tab. You can then put it in the
OnAction property of any button in your database with =abc().

Another possible alternative for you would be to us the same commandbar for all
your forms. If you make the commandbar a menubar you can go to the Other tab in
properties and set the menubar for the form to the name of your common
commandbar. Then you only need one button on the common commandbar that executes
abc() and you will be able to execute abc() from all your forms.
 
Albert said:
Many of my forms contain the same public function name, say abc(), and
purpose is to be assigned to On Action of a specific CommandBarButton of
each Form's CommandBar. Do I have to write any prefix to abc() , such as
Form1.abc() , to let Access know this abc() is of Form1. Actually, I have
tried, But Access can not recognize this format (Form1.abc()).


I seem to remember that you can just use the name of the
function and the command bar will first look in the form
that has the focus for the function, then it will look for a
public function in a standard module. Give it a try and see
if my memory is still working ;-)

If the code in all the forms is the same, then you would be
better off moving the function to a standard module. If the
function needs to "know" what form had the focus when the
command bar was clicked, it can refer to the
Screen.ActiveForm object
 
Marshall got this about right.
I seem to remember that you can just use the name of the
function and the command bar will first look in the form
that has the focus for the function, then it will look for a
public function in a standard module. Give it a try and see
if my memory is still working ;-)

Your memory seems quite fine!

The only thing to add to the above is that you MUST make the function public
in the forms module. The beauty of this is that you can use the same menu
bar for several forms, but different code will run, since whatever form has
the focus, the correct code will run. So, if you need different code for
different forms, then put the function in the form,and make it public.

If all the code is the same for all forms, then of course one would put the
code into a standard module.

Also, do NOT put a full forms qualifying name, as you will get bitten my
this little nasty bug:

http://www.mvps.org/access/bugs/bugs0048.htm
 
Back
Top