Menu running Code

A

AJ

This seems like an easy thing - I am sure it is.

I am trying to get my menus to run some code that I wrote using a command
button wizard...
I Google this group, and learned that I merely refer to a PUBLIC sub in the
menus on-action field...

for example:
=MyInvoicePrint()

But it doesn't work.
I have tried variations that included the click, like
=MyInvoicePrint_click(), and everything.

What is the hitch? Does it have to be tied to a form?
 
A

Albert D.Kallal

AJ said:
This seems like an easy thing - I am sure it is.

I am trying to get my menus to run some code that I wrote using a command
button wizard...
I Google this group, and learned that I merely refer to a PUBLIC sub in
the menus on-action field...

Ah, public Function you need!!

Make the code as a function. You can call a function in a sql expression, or
in fact anywhere you want....
for example:
=MyInvoicePrint()
What is the hitch? Does it have to be tied to a form?

You can put the code in a form's module, or a standard module. (the code is
looked for in the form first).
 
A

AJ

How do I do that? replace the word "Sub" with "Function"? or just move all
the code to the "Module" window pane? [very newbie question.]

(but thanks for this insight)
 
A

Albert D.Kallal

AJ said:
How do I do that? replace the word "Sub" with "Function"? or just move all
the code to the "Module" window pane? [very newbie question.]

Yes, you have to declare the code you want to run as a function.

If you have a complex application as is, then you don't dare change a sub to
a function, as this could break other code that uses the sub.

What you can do in the above case is simply make a public function that
calls the sub for you!

however, if no other code is using the sub, then simply change it to a
function, and you should be good to go...

So, if you are JUST calling the code from a menu bar etc, then simply
declare the code as a public function.


Public Function MyHello()

msgbox "hello"

end function


You then put the name of he function in the menus on-action.

So,

=MyHello()

Most of the time, it makes sense to declare your code routines as a sub,
since they do NOT return any values. However, the one exception to this rule
is for menu bars etc, as they requite you to use a public function ( I wish
this was not so..but it is minor thing at the end of the day).
 

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