469,304 Members | 1,796 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,304 developers. It's quick & easy.

CallByName to Module rather than to Form

I use the CallByName function quite regularly, but the sub routines
that I have always called have been located within the form code. The
call I use looks something like this:

Dim CallObjectForm As Form
Set CallObjectForm = Forms("My Form")
CallByName CallObjectForm, "My_Form_SubRoutineCall", VbMethod

I now want to call code that is located within a standard module and I
am not having any luck. I'm trying to use the following code:

Dim CallObjectModule As Module
Set CallObjectModule = Modules("My Module")
CallByName CallObjectModule, "My_Module_SubRoutineCall", VbMethod

Thanks for any ideas!

Nov 13 '05 #1
5 11351
Edlueze wrote:
I use the CallByName function quite regularly, but the sub routines
that I have always called have been located within the form code. The
call I use looks something like this:

Dim CallObjectForm As Form
Set CallObjectForm = Forms("My Form")
CallByName CallObjectForm, "My_Form_SubRoutineCall", VbMethod

I now want to call code that is located within a standard module and I
am not having any luck. I'm trying to use the following code:

Dim CallObjectModule As Module
Set CallObjectModule = Modules("My Module")
CallByName CallObjectModule, "My_Module_SubRoutineCall", VbMethod

Thanks for any ideas!


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The CallByName only works w/ class objects. A standard module is not
considered a class object. You can call a routine in a standard module
using the following syntax:

Function w/ return:

variable = ModuleName.FunctionName <(params)>

Sub:

ModuleName.SubName <params>

<> indicates optional.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQnaAMIechKqOuFEgEQIUPACglyBLh4vliGCrH/UAytT593WG6gMAnAwV
jN/QDY0Xd9kOe4BKpvcjbTkF
=yq5t
-----END PGP SIGNATURE-----
Nov 13 '05 #2
Thanks for the response. I use the CallByName routine to call a Sub
routine via a string that contains the name of the Sub routine. Is
there any way to call a Sub routine that is physically located in a
standard module (as opposed to a Form or Report) in this way (ie with a
string containing "Sub_Name")? Do the Form or Report class objects
somehow inherit the standard module routines?

Thanks!

Nov 13 '05 #3
Edlueze wrote:
Thanks for the response. I use the CallByName routine to call a Sub
routine via a string that contains the name of the Sub routine. Is
there any way to call a Sub routine that is physically located in a
standard module (as opposed to a Form or Report) in this way (ie with a
string containing "Sub_Name")? Do the Form or Report class objects
somehow inherit the standard module routines?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You can use the Eval() function:

strProcedure = "FunctionName()"
Eval(strProcedure)

The routine in the Eval() function has to be the name of a Function not
a Sub.

If you "know" the name of the procedure you want to run & where it is,
which it seems you do, why not use:

ModuleName.RoutineName

?? This was stated in my first response to you're original post.

E.g.:

intRound = Math.Round(dblPercentage,2)

Which calls the Round() function in the module Math and returns the
results into the intRound variable.

The Form/Reports do NOT inherit standard modules. There is no
inheritance in Access.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQnaTlYechKqOuFEgEQIWvgCg5oEpVAnJXqzchsWDaJtnN2 XvlSQAoLOd
mbEBCJEIA/8OcnUZ7f3Cwe5c
=fc1l
-----END PGP SIGNATURE-----
Nov 13 '05 #4
Great! Eval() works perfectly - I learn something new everyday.

Let me try and help you understand what I'm doing: 99% of the time I am
using a direct call to the procedure as you suggest. But the remaining
1% of the time I call the procedure via CallByName. In these situations
I have a pop-up that can be opened by any one of a number of forms, and
when that pop-up closes it needs to make a return call to the form that
opened it. I pass the name of the calling form and return sub routine
via two strings (actually more because I need to take into account
parent forms and grandparent forms). This allows me to use the same
pop-up to gather information in a standard way for lots of different
calling forms.

I ran into this particularly problem when I tried extending the basic
workflow to Controlbars. I put the code that manages my Controlbars
into standard modules rather than into the forms like everything else,
so the return call needed to be made to the standard module. This is
where I ran into trouble! The Eval() function now allows me to do this,
whereas the CallByName only allowed me to make the return call to a
form.

Nov 13 '05 #5
On 2 May 2005 20:59:31 -0700, "Edlueze" <ed*****@onegen.com> wrote:
Great! Eval() works perfectly - I learn something new everyday.

Let me try and help you understand what I'm doing: 99% of the time I am
using a direct call to the procedure as you suggest. But the remaining
1% of the time I call the procedure via CallByName. In these situations
I have a pop-up that can be opened by any one of a number of forms, and
when that pop-up closes it needs to make a return call to the form that
opened it. I pass the name of the calling form and return sub routine
via two strings (actually more because I need to take into account
parent forms and grandparent forms). This allows me to use the same
pop-up to gather information in a standard way for lots of different
calling forms.

I ran into this particularly problem when I tried extending the basic
workflow to Controlbars. I put the code that manages my Controlbars
into standard modules rather than into the forms like everything else,
so the return call needed to be made to the standard module. This is
where I ran into trouble! The Eval() function now allows me to do this,
whereas the CallByName only allowed me to make the return call to a
form.


Just one more note...

The Eval solution works in Access, and there are similar functions in VBA for
other Office products, but there's no similar function in VB. If you ever
find you want to use CallByName in VB, just arrange for the procedure to be
called to be in a class instance. You can keep an instance of the class in a
global variable contained in a standard module.

Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Judy | last post: by
4 posts views Thread by Brad Parks | last post: by
2 posts views Thread by ej | last post: by
1 post views Thread by Timberwoof | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.