To the well once more: Switchboard command to run code

M

MikeB

I finally(!) have my first piece of VBA code running. (I might post it
sometime and ask for ways to improve it).

Now I'm trying to automate running this code by having a button on my
switchboard.

THere is an option to "Run Code", but I just cannot figure out what to
put in the "function Name" box.

I started with a Module named RatePlayers and a main routine in there
named x1: RatePlayers.x1 : There was an error executing the command.

Then I tried x1: There was an error...

Then I tried RatePlayers: There was an error

Then I renamed the Sub to RatePlayers: There was an Error

Then I changed from a Sub to a Function: There was an error....

Now I
m plumb outta ideas.

What do I have to call the module and the main routine within that
module and how do I specify the correct name in the Switchboard
manager to get it to run the code?

Thank you so much.
 
D

Douglas J. Steele

Sorry, but you're going to have to provide more information. "There was an
error" really doesn't tell anyone anything.

The name of the module is (mostly) irrelevant: you're running the sub or
function, not the module. The "mostly" part is simply because you cannot
name a module the same as any sub or function in the application, but a
module name of "RatePlayers" with a procedure name of x1 should have be
fine. It was definitely a mistake to have renamed the sub to RatePlayers,
and if you left the function name as RatePlayers, change it back to x1 and
then try to run it.
 
M

MikeB

Sorry, but you're going to have to provide more information. "There was an
error" really doesn't tell anyone anything.

Sorry about that. It was one of those super-uninformative messages. It
literally said "There was an error executing the command."

The name of the module is (mostly) irrelevant: you're running the sub or
function, not the module. The "mostly" part is simply because you cannot
name a module the same as any sub or function in the application, but a
module name of "RatePlayers" with a procedure name of x1 should have be
fine. It was definitely a mistake to have renamed the sub to RatePlayers,
and if you left the function name as RatePlayers, change it back to x1 and
then try to run it.

So this morning I change it (following your advice above) to
runRatings (thought that was a tad more descriptive) and lo and
behold, it worked. So then I figured it out. I had as part of all the
testing I had done, written several x1 subs, since they were simply
tests and I'm not good at coming up with descriptive names. Or if I
do, they tend to be names already in use.

So thanks to all here. I've got another part of my little app running
smoothly.

Woot!
 
L

Larry Linson

What Doug was saying is that a Module is just a container for Sub Procedures
and Function Procedures -- you execute the Sub or Function, not the Module.
Unlike some programming languages of the past, there is no implied "main"
procedure in a module.

Larry Linson
Microsoft Office Access MVP
 
K

Klatuu

One thing not discussed, Larry, is that if the switchboard manager runcode
is like the macro runcode, the procedure name must refer to a function, not
a sub. But since I have only used a switchboard when it preceeded me, I
don't really know if that is the case.
 
D

David W. Fenton

What Doug was saying is that a Module is just a container for Sub
Procedures and Function Procedures -- you execute the Sub or
Function, not the Module. Unlike some programming languages of the
past, there is no implied "main" procedure in a module.

The Switchboard manager can only call Functions not Subs.
 
M

MikeB

One thing not discussed, Larry, is that if the switchboard manager runcode
is like the macro runcode, the procedure name must refer to a function, not
a sub. But since I have only used a switchboard when it preceeded me, I
don't really know if that is the case.

Funny you should say this. I ran across this very issue. Since the
program didn't produce any visual output, I decided to replace it with
a macro that would run the program and then open the report to display
the output.

The macro wouldn't run the Sub that the switchboard would run. SO I
coded a little Function that simply called the Sub and all was hunky-
dory. I saw some discussion somewhere on a way to change the
switchboard code to run functions, but I figured I'd rather pass.

So you are right, Switchboards run Subs and Macros run Functions.
Unless you mod the Switchboard.
 
L

Larry Linson

MikeB said:
Now I'm trying to automate running this code by
having a button on my switchboard.

I just realized I had not determined, before replying, whether you were
talking about a switchboard generated with the Switchboard Manager, and just
assumed it was your own, original switchboard you created using forms and
controls. I do not use the Switchboard Manager, as I believe it to be (at
best, and charitably put) a "complex solution to a simple problem". Now I
see it does appear you used the Switchboard Manager, so I'll just advise
that my previous responses do not apply, and drop out of this thread. My
advice on Switchboard Manager is "don't bother; create your own with unbound
forms and command buttons and other controls".

Larry Linson
Microsoft Office Access MVP
 

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