How to load a code module (manually)?

  • Thread starter Thread starter nieurig
  • Start date Start date
N

nieurig

Hi forum,
i use Access 97 and all of my menueitems call functions
(=ShowData1() ...) from a specific modul (.M_Menue ). If
any form is open this work fine. But, if all forms are
closed i get the error message "unknown or misspelling
function". Access don't find the existing function into
the code module.

I assume that the code module was automatically load if a
form was opened (but not if a menue was used) and will
unload if all forms are closed.

How can i load a module by code and prevent an unload?

Thank you very much for any help.
Niels
 
I don't see why a form has to be opened to call some code. There is some
detail, or something else here not quite clear.

In your menus on-action setting, you can as you show, just put the name of a
public function:

=ShowDate1()

However, if the above routine is in fact in the FORM'S module code, then
yes, of course, the form must be opened before the above will work. Are you
sure this code exists in a standard module, and not a forms module?

There is no special need to "load" a standard module. Any public function in
those modules can be used in menu code, forms, and even expressions in sql.
 
Hi Albert,
case your comment i found my mistake.
Thanks for your help.
In your menus on-action setting, you can as you show,
just put the name of a ***public*** function:
=ShowDate1()
I forget to set the functions to public. Functions without
this attribute shows the behaivor, i told about.


2 additional questions:
Are you sure this code exists in a standard module,
and not a forms module?

You (and the documentation of Access) use the
idiom "Standard Module". Are all Modules at the
Tab-Riegister "Modules" Standard Modules?

Is there a way to set a module at the
Module-Tab to a "not standard Module?"


Once more. Thank a lot for your help!
Niels
 
You (and the documentation of Access) use the
idiom "Standard Module". Are all Modules at the
Tab-Riegister "Modules" Standard Modules?

Is there a way to set a module at the
Module-Tab to a "not standard Module?"

Yes, a standard module is simply the modules you find in the module tab.

There is also what we call a form level module, and that is simply where all
the code for events for a particular form goes. Note that you CAN in fact
define public functions in a form, and your menu code will thus run the
function in the current form, and NOT use a the standard module function. If
for example you had two functions with the exact same name, then the form
module one will run. This feature can be put to good use, since then each
form can have a standard set of functions that you run from the menu bar,
but each form can thus have its custom code, but use the same menu bar. In
general, for menu bars that are attached to a particular form, I fo place
the functions for that menu bar also in the forms module (this keeps the
code for the form in one easy to find spot, and thus I don't have to use, or
put code in a standard module). Note that the functions still have to be
declared as public in the forms module to be run from the menu bar.

Thus, more "general" type code belongs in standard modules.
 
Hi Albert,
thanks for your discription of using form-modules and
standard-modules.
What a great newsgroup this is. :-))) Beside of good
comments i got details about good strategies of
programming. Thanks for this.


place the functions for that menu bar
also in the forms module (this keeps the
code for the form in one easy to find spot,
and thus I don't have to use, or
put code in a standard module).

I prefer to put all the code to Standard-modules and call
it from the form-module.

The reason for this are the lot of mouse clicks to close
module and form after editing the code.

In addition i avoid to get problems with code chances
after getting runtime errors. If a codeline of a form
module fires a error and i correct the code in the opened
source window i have problems to save it. Sometimes the
code was saved sometimes not.

Niels
 
Back
Top