Call a Function from string variable 
Author Message
 Call a Function from string variable

Hi all--

I know I can use the Eval function or Application.Run method to call a
function using a string variable. My question, however, is:

How do you call a function from a *specific* module?

In the event that there is an identically named function in a different
module, I want to ensure that function "X" is called from, say, from module
"Y", instead of calling function "X" from module "Z".

--
Robert R. Thele


[Remove NoSpam_ to reply via E-mail]



Tue, 04 Jun 2002 03:00:00 GMT  
 Call a Function from string variable
By putting the module  name in front of the function, separated by a dot.
---Phil S.


Quote:
> Hi all--

> I know I can use the Eval function or Application.Run method to call a
> function using a string variable. My question, however, is:

> How do you call a function from a *specific* module?

> In the event that there is an identically named function in a different
> module, I want to ensure that function "X" is called from, say, from
module
> "Y", instead of calling function "X" from module "Z".

> --
> Robert R. Thele


> [Remove NoSpam_ to reply via E-mail]



Tue, 04 Jun 2002 03:00:00 GMT  
 Call a Function from string variable
Hi Phil--

I tried that but the following scenarios result in these errors:

Modules Names        Function Name
    Module1                    FunctionX
    Module2                    FunctionX

Tried:    Application.Run "FunctionX"
            Application.Run "Module1.FunctionX"
            Application.Run "Module2.FunctionX"
Error:    # 2517 Access can't find procedure 'XXXXXXX'

Tried:    Eval("FunctionX")
            Eval("Module1.FunctionX")
            Eval("Module2.FunctionX")
Error:    # 2482 Access can't find procedure 'XXXXXXX' you entered in
expression

Where XXXXXX is the first name (function or module) in the parameter.

Both the calls work if FunctionX exists in only ONE module.

FWIW, A2000 does not catch the ambiguous/duplicated name during compilation.
It does however issue an "Ambiguous Name'" error if you try to run the
function at run time (which is a little too late, IMHO).

How do you pros handle such "Ambiguous Name'" in Access, when one could
easily import a function that would cause duplication. Do you prefix ALL
sub/function calls with module names?

--
Robert R. Thele


[Remove NoSpam_ to reply via E-mail]

Quote:
> By putting the module  name in front of the function, separated by a dot.
> ---Phil S.



> > Hi all--

> > I know I can use the Eval function or Application.Run method to call a
> > function using a string variable. My question, however, is:

> > How do you call a function from a *specific* module?

> > In the event that there is an identically named function in a different
> > module, I want to ensure that function "X" is called from, say, from
> module
> > "Y", instead of calling function "X" from module "Z".

> > --
> > Robert R. Thele


> > [Remove NoSpam_ to reply via E-mail]



Tue, 04 Jun 2002 03:00:00 GMT  
 Call a Function from string variable
I don't use the same name twice in an mdb.

Try:
Call Module2.FunctionX
--
Joe
Access MVP
Check out Dev Ashish's web site for answers to common questions
http://www.mvps.org/access/


Quote:
> Hi Phil--

> I tried that but the following scenarios result in these errors:

> Modules Names        Function Name
>     Module1                    FunctionX
>     Module2                    FunctionX

> Tried:    Application.Run "FunctionX"
>             Application.Run "Module1.FunctionX"
>             Application.Run "Module2.FunctionX"
> Error:    # 2517 Access can't find procedure 'XXXXXXX'

> Tried:    Eval("FunctionX")
>             Eval("Module1.FunctionX")
>             Eval("Module2.FunctionX")
> Error:    # 2482 Access can't find procedure 'XXXXXXX' you entered in
> expression

> Where XXXXXX is the first name (function or module) in the parameter.

> Both the calls work if FunctionX exists in only ONE module.

> FWIW, A2000 does not catch the ambiguous/duplicated name during
compilation.
> It does however issue an "Ambiguous Name'" error if you try to run the
> function at run time (which is a little too late, IMHO).

> How do you pros handle such "Ambiguous Name'" in Access, when one could
> easily import a function that would cause duplication. Do you prefix ALL
> sub/function calls with module names?

> --
> Robert R. Thele


> [Remove NoSpam_ to reply via E-mail]


> > By putting the module  name in front of the function, separated by a
dot.
> > ---Phil S.



> > > Hi all--

> > > I know I can use the Eval function or Application.Run method to call a
> > > function using a string variable. My question, however, is:

> > > How do you call a function from a *specific* module?

> > > In the event that there is an identically named function in a
different
> > > module, I want to ensure that function "X" is called from, say, from
> > module
> > > "Y", instead of calling function "X" from module "Z".

> > > --
> > > Robert R. Thele


> > > [Remove NoSpam_ to reply via E-mail]



Tue, 04 Jun 2002 03:00:00 GMT  
 Call a Function from string variable
Doesn't a fucntion always return a value? Then perhaps something like:
    dim iAns as Integer
    iAns = Module1.FunctionX
---Phil S.


Quote:
> Hi all--

> I know I can use the Eval function or Application.Run method to call a
> function using a string variable. My question, however, is:

> How do you call a function from a *specific* module?

> In the event that there is an identically named function in a different
> module, I want to ensure that function "X" is called from, say, from
module
> "Y", instead of calling function "X" from module "Z".

> --
> Robert R. Thele


> [Remove NoSpam_ to reply via E-mail]



Tue, 04 Jun 2002 03:00:00 GMT  
 Call a Function from string variable

Quote:
> > How do you pros handle such "Ambiguous Name'" in Access, when
one could
> > easily import a function that would cause duplication. Do you
prefix ALL
> > sub/function calls with module names?

EASILY? well, if you follow the convention of naming procedures
according to their functionality, then the number of duplicates
should be rare.

--
MichKa

don't ask by e-mail unless you're paying for it. (TANSTAAFL!) :-)

random junk of dubious value, a multilingual website, the
worldwide TSI Form/Report to Data Access Page Wizard,
and lots of replication "stuff" at http://www.trigeminal.com/



Tue, 04 Jun 2002 03:00:00 GMT  
 Call a Function from string variable
In a standard module, ModuleName.FunctionName cannot be used to
disambiguate. You cannot have two objects with the same name at the
same level of scope -- not two public variables in standard modules
either. The dot syntax will only help with class modules, because
separate instances are created whenever an object is created from the
class.

 -- Andy

Quote:

>Hi all--

>I know I can use the Eval function or Application.Run method to call a
>function using a string variable. My question, however, is:

>How do you call a function from a *specific* module?

>In the event that there is an identically named function in a different
>module, I want to ensure that function "X" is called from, say, from module
>"Y", instead of calling function "X" from module "Z".

>--
>Robert R. Thele


>[Remove NoSpam_ to reply via E-mail]



Sat, 08 Jun 2002 03:00:00 GMT  
 Call a Function from string variable
That's odd.  Investigating this problem, I created two like-named functions
in two different standard modules (A97).  Compiled and saved each.  In the
Debug window, I successfully invoked each using the syntax

   ?ModuleName.DupFunc()

However, when I tried to use Eval("ModuleName.DupFunc()"), then it didn't
work.

--

Quote:

>In a standard module, ModuleName.FunctionName cannot be used to
>disambiguate. You cannot have two objects with the same name at the
>same level of scope -- not two public variables in standard modules
>either. The dot syntax will only help with class modules, because
>separate instances are created whenever an object is created from the
>class.

> -- Andy


>>Hi all--

>>I know I can use the Eval function or Application.Run method to call a
>>function using a string variable. My question, however, is:

>>How do you call a function from a *specific* module?

>>In the event that there is an identically named function in a different
>>module, I want to ensure that function "X" is called from, say, from
module
>>"Y", instead of calling function "X" from module "Z".

>>--
>>Robert R. Thele


>>[Remove NoSpam_ to reply via E-mail]



Sat, 08 Jun 2002 03:00:00 GMT  
 Call a Function from string variable
Thanks for testing that. In fact, I found that using
ModuleName.VariableName even allows you to have multiple public
variables in standard modules with the same name. I don't think this
was always so, and perhaps that is why Eval doesn't support it. But it
should.

 -- Andy

Quote:

>That's odd.  Investigating this problem, I created two like-named functions
>in two different standard modules (A97).  Compiled and saved each.  In the
>Debug window, I successfully invoked each using the syntax

>   ?ModuleName.DupFunc()

>However, when I tried to use Eval("ModuleName.DupFunc()"), then it didn't
>work.

>--


>>In a standard module, ModuleName.FunctionName cannot be used to
>>disambiguate. You cannot have two objects with the same name at the
>>same level of scope -- not two public variables in standard modules
>>either. The dot syntax will only help with class modules, because
>>separate instances are created whenever an object is created from the
>>class.

>> -- Andy


>>>Hi all--

>>>I know I can use the Eval function or Application.Run method to call a
>>>function using a string variable. My question, however, is:

>>>How do you call a function from a *specific* module?

>>>In the event that there is an identically named function in a different
>>>module, I want to ensure that function "X" is called from, say, from
>module
>>>"Y", instead of calling function "X" from module "Z".

>>>--
>>>Robert R. Thele


>>>[Remove NoSpam_ to reply via E-mail]



Tue, 11 Jun 2002 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Call a Function from string variable

2. Call a Function from string variable

3. Calling function or sub with variable array or string names

4. how do i call a function by using the function name as a string of characters

5. Call Let/Get Prop using string variable for name

6. Call Let/Get Prop using string variable for name

7. Call a proc using a string variable for the proc name

8. Call Module Function using string value

9. Call function by name as a string

10. Queries and Calling Functions : Concatenating Strings within the same fields


 
Powered by phpBB® Forum Software © phpBB Group