Call module functions from outside of module? 
Author Message
 Call module functions from outside of module?

I have a couple of functions, such as IsLoaded (for a form), which are truly
generic and called by all of my forms.

At the moment I have a copy of the function inside of the module of each
form.  The problem, as you can imagine, is that when I need to modify this
function I have to modify the copy in each and every form of the database.

Is there some way I can place this function in a module and then call it
from each form?  I know how to call a module function with a macro but I
can't figure out how to do it inside the VBA module of a form.

Thank you for any suggestions you may have.

-----
Please reply via EMail *AND* Newsgroup if possible.


Paris, FRANCE                      Web: http://www.*-*-*.com/



Sun, 03 Sep 2000 03:00:00 GMT  
 Call module functions from outside of module?

Hi,

Just need to paste that function inside a new module.  If you want, you can
add Public before the Function declaration.  Just don't use Private in
modules as that renders the sub/function "private" to that module.  Usage
will remain the same as if the function was within the form's itself.

For example,
Option Compare Database
Option Explicit

Public Function IsVisible(intObjType As Integer, strObjName As String) As
Boolean
Dim intObjState As Integer
    intObjState = SysCmd(acSysCmdGetObjectState, intObjType, strObjName)
    IsVisible = intObjState And acObjStateOpen
End Function

and you should be able to call IsVisible from anywhere in the database.

HTH
--
Just my $.001
Please limit questions to newsgroups only!
Dev Ashish
---------------
The Access Web ( http://home.att.net/~dashish )
---------------

:I have a couple of functions, such as IsLoaded (for a form), which are
truly
:generic and called by all of my forms.
:
:At the moment I have a copy of the function inside of the module of each
:form.  The problem, as you can imagine, is that when I need to modify this
:function I have to modify the copy in each and every form of the database.
:
:Is there some way I can place this function in a module and then call it
:from each form?  I know how to call a module function with a macro but I
:can't figure out how to do it inside the VBA module of a form.
:
:Thank you for any suggestions you may have.
:
:
:-----
:Please reply via EMail *AND* Newsgroup if possible.
:

:Paris, FRANCE                      Web: http://www.erb.com
:
:
:



Sun, 03 Sep 2000 03:00:00 GMT  
 Call module functions from outside of module?

There are a couple of ways to do this:

Create a module and add a function:

Public Function MyFunc()
...

In the event property type this: =MyFunc()

OR

Double click on the event prpoerty name. This will add the text
[Event Procedure] to the property setting. then click the ellipsis
(...) to get to the event handler. Then, in eacy of your forms,
add this code:

MyFunc.

Using the second approach, you can use a SUB or a Function.

Jim Bailey

Quote:

> I have a couple of functions, such as IsLoaded (for a form), which are truly
> generic and called by all of my forms.

> At the moment I have a copy of the function inside of the module of each
> form.  The problem, as you can imagine, is that when I need to modify this
> function I have to modify the copy in each and every form of the database.

> Is there some way I can place this function in a module and then call it
> from each form?  I know how to call a module function with a macro but I
> can't figure out how to do it inside the VBA module of a form.

> Thank you for any suggestions you may have.

> -----
> Please reply via EMail *AND* Newsgroup if possible.


> Paris, FRANCE                      Web: http://www.erb.com



Sun, 03 Sep 2000 03:00:00 GMT  
 Call module functions from outside of module?

You should be able to use the function just the way you use it when it's
included in the form module, as long as it's not declared as a private
function .. as in

if isLoaded("somefrmName") then
    do something
else
    do something else
end if

You say you use it in every form. I have never found a use for this
function. MS uses it in their instructional NorthSomething Database, but
only to see if a form is operating as a subform or a standalone, and
forbidding data change in the standalone. I've never investigated why MS
wants to forbid data change in the standalone, maybe it's because their
cascading updates and deletes won't work there. So, would you tell us, or at
least me, what you use this function for?
--
Lyle Fairfield

Quote:

>I have a couple of functions, such as IsLoaded (for a form), which are
truly
>generic and called by all of my forms.

>At the moment I have a copy of the function inside of the module of each
>form.  The problem, as you can imagine, is that when I need to modify this
>function I have to modify the copy in each and every form of the database.

>Is there some way I can place this function in a module and then call it
>from each form?  I know how to call a module function with a macro but I
>can't figure out how to do it inside the VBA module of a form.

>Thank you for any suggestions you may have.

>-----
>Please reply via EMail *AND* Newsgroup if possible.


>Paris, FRANCE                      Web: http://www.erb.com



Sun, 03 Sep 2000 03:00:00 GMT  
 Call module functions from outside of module?


says...

Quote:
> Is there some way I can place this function in a module and then call it
> from each form?  I know how to call a module function with a macro but I
> can't figure out how to do it inside the VBA module of a form.

Sure.  Just create a new module, and add your "shared" routine to that
module.  I'd also add a Public keyword, to make it clear from reading
that this is available outside this module (but it is, by default,
anyway):

Public Function IsLoaded(.....

Then, delete the function from all the forms that use it. -- Ken



Sun, 03 Sep 2000 03:00:00 GMT  
 Call module functions from outside of module?


Quote:
>You should be able to use the function just the way you use it when it's
>included in the form module, as long as it's not declared as a private
>function .. as in

>if isLoaded("somefrmName") then
>    do something
>else
>    do something else
>end if

Thank you very much for your helpful response... especially for e-mailing me
it as well!  I knew it would be something stupid like that.  I kept trying
to find out how to add the module name before the function name to tell the
system which module to look in to find the function.  The simpler method
obviously works.

This brings up another question:  I can place a public IsLoaded function in
one module in my database.  I can also place a public IsLoaded function,
with the same parameters, in a different module in the same database.  If I
use IsLoaded("someformname") in a form I then am told that I'm using an
"ambivalent function name"... which I agree with.  How could I tell it which
module to look in to if I really needed to?

Quote:
>So, would you tell us, or at least me, what you use this function for?

We have a main form which is opened automatically when the database is
opened.  This is a "switchboard" style form with a bunch of buttons on it.
Each button opens a relevant form.  For example if you click on the
"Companies" button it opens the "Companies" form.  When each button opens
the relevant form it also places the main form as invisible.  It is still
loaded but invisible.  Each form which is called by the switchboard form
therefore verifies, in its OnClose method if the main form is loaded.  If
the main form is loaded it makes it visible upon closing... if it isn't it
does not try and reference it which would create an error.

You get the idea...

Thank you again for your valuable assistance.

-----
Please reply via EMail *AND* Newsgroup if possible.


Paris, FRANCE                      Web: http://www.erb.com



Mon, 04 Sep 2000 03:00:00 GMT  
 Call module functions from outside of module?

Guess I'm not a purist. I use the same visible-hidden scheme, but just use:
On Error Resume Next
to deal with the situation in which the main form is not loaded.
Since the error is really inconsequential, this seems to work
satisfactorily, and is probably a bit faster.

As to putting two  copies of the same public function in different modules,
the question of "Why?" raises itself again.

If it were important to do this, I believe you could accomplish it by
writing class modules and specifying isLoaded as a property of each. You
would have to write a Property Get for each. Then you could use the one or
the other as in:
Class1.IsLoaded("Main")
or
Class2.IsLoaded("Main")

I think!!!!
--
Lyle Fairfield


Quote:
>Thank you very much for your helpful response... especially for e-mailing
me
>it as well!  I knew it would be something stupid like that.  I kept trying
>to find out how to add the module name before the function name to tell the
>system which module to look in to find the function.  The simpler method
>obviously works.

>This brings up another question:  I can place a public IsLoaded function in
>one module in my database.  I can also place a public IsLoaded function,
>with the same parameters, in a different module in the same database.  If I
>use IsLoaded("someformname") in a form I then am told that I'm using an
>"ambivalent function name"... which I agree with.  How could I tell it
which
>module to look in to if I really needed to?

>>So, would you tell us, or at least me, what you use this function for?

>We have a main form which is opened automatically when the database is
>opened.  This is a "switchboard" style form with a bunch of buttons on it.
>Each button opens a relevant form.  For example if you click on the
>"Companies" button it opens the "Companies" form.  When each button opens
>the relevant form it also places the main form as invisible.  It is still
>loaded but invisible.  Each form which is called by the switchboard form
>therefore verifies, in its OnClose method if the main form is loaded.  If
>the main form is loaded it makes it visible upon closing... if it isn't it
>does not try and reference it which would create an error.



Mon, 04 Sep 2000 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Calling a Function in an MS Access Class/Form/Module from an outside application

2. Calling Modules & Macros from outside Access

3. Using Module functions inside/outside VB ActiveX DLL

4. Modules, Modules, Modules

5. trouble calling a function in a module

6. Calling module functions from SQL through ADO

7. Form call function in module of another database

8. Referencing the Form from Which a Module Function Is Called

9. Calling a function in a usercontrol from out a module

10. How to call a function of another module?

11. Calling a C function from a VB module

12. Module Call Function of Usercontrol

 

 
Powered by phpBB® Forum Software