Autoexec sub

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This is probably simple, but I'm stumped. How do you automatically execute a
sub on load? None of the "Run" commands in the action drop down for the
Autoexec macro seem to work with a sub.

Thanks
Vern
 
Vern said:
This is probably simple, but I'm stumped. How do you automatically
execute a sub on load? None of the "Run" commands in the action drop
down for the Autoexec macro seem to work with a sub.

Thanks
Vern

Make it a function. All it takes is changing a few words.
 
Rick:

Thanks. That worked... kinda. When I create a function in a "local" module,
it works. But I have a reference to another Access database, in which the sub
(now function) resides. I can't seem to have the referenced one show up as a
function for the Autoexec macro. Suggestions?

Thanks
Vern Rabe
 
Vern said:
Rick:

Thanks. That worked... kinda. When I create a function in a "local"
module, it works. But I have a reference to another Access database,
in which the sub (now function) resides. I can't seem to have the
referenced one show up as a function for the Autoexec macro.
Suggestions?

How are you referrring to it? Are you inlcuding the referenced file in the call
like....

=FileName.Function()
 
Rick:

By going to the Visual Basic Editor, Tools menu, References... menu, and
adding a reference to the .mdb that has the function.

Vern
 
Vern said:
Rick:

By going to the Visual Basic Editor, Tools menu, References... menu,
and adding a reference to the .mdb that has the function.

I'm not certain that you don't still need to include the file name in the call.
 
Rick:

When I go to design mode for the AutoExec macro, and select RunCode as the
action, I am given a Function Name control to fill in. When I select the
ellipsis in the control, it takes me to the Expression Builder window. There
I can select only local functions (functions in referenced applications are
not listed). If, back in the Function Name control, I explicitly type in
"fnX()", it will run the local fnX function. If I instead type in
"=RefApp.fnX()", attempting to save will result in an error message that
Access cannot parse it. By eliminating the equal sign, and typing in
"RefApp.fnX", the expression is parsed, but when I open the application I get
an error that it can find the name "fnX". Could it be that Access is trying
to run the code before the referenced code has been retrieved?

Thanks
Vern Rabe
 
Try creating a function in your local application that calls the function
from the referenced application and call it from the AutoExec.

That should indicate if it's trying to run too soon.
 
Douglas:

I tried that, and it worked. My local function executes "intVar =
FileName.ModName.fnX()". As a test, I then put a second action in the
AutoExec, this one a RunCode that directly calls the referenced function
(what I've been trying to do all along). On the assumption that the actions
are executed synchronously, and since the first action includes a call to the
referenced file, then when it comes time to run the second action, I'm
assuming the referenced file has to be fully loaded. When I start the
application with those in place I get the same
"...can't find the name..." error. Does this mean my syntax is incorrect? Or
it simply won't work this way?

I have hundreds of Access apps that need to have this code run on startup.
My hope is to go to each app, add a reference to my "shared" app, and add a
RunCode action to the AutoExec macro. If that doesn't work, and I need to
implement something like your Douglas', I would go to each app, add a
reference to my "shared" app, add a module (most apps won't have one), add a
function in this new module that calls the referenced app, and add a RunCode
action to the AutoExec macro to run the new local function. Definitely
doable, but more work, and if direct autoexec of a referenced function should
work, I'd rather get it to work. So... should I stop here and implement this,
or does anyone have any other ideas?

Thanks
Vern Rabe
 
As long as fnX doesn't exist in your local database and you've added a
reference to the other database, fnx() should be sufficient to get it to
run.
 
Back
Top