472,342 Members | 1,446 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

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 11881
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Bob | last post by:
Declaring a module level form object in multiple froms within a project to show another project form causes a stack overflow and other assorted...
9
by: MLH | last post by:
Would the following work if placed in a form module rather than a global module? Declare Sub InternetCloseHandle Lib "wininet.dll" (ByVal hInet...
3
by: JimF | last post by:
I need to scan a couple of hundred databases in several directories to locate all code that uses a particular function, but cannot figure out how...
2
by: Judy | last post by:
I have a custom menu that is only used for one form. Is there a way to put the functions for the menu items in the form's module rather than a...
4
by: Brad Parks | last post by:
Are there any performance or memory-usage benefits of placing public functions and subroutines in a Class Module rather than a standard module?
1
by: Marcin | last post by:
Hello all! I have unusual problem with a database form. I have a few forms with charts. I`ve created a module which changes me a chart title. I...
2
by: ej | last post by:
I'm not seeing how to get at the 'name' attribute of an HTML <form> element. form = cgi.FieldStorage() gives you a dictionary-like object that...
1
by: Timberwoof | last post by:
For i = 1 To 3 CallByName(Form1.Controls("ComboBox" & i), "items.add", Type.Set, "1st item") CallByName(Form1.Controls("ComboBox" & i),...
2
by: luckilian | last post by:
hi guys, i have a problem .. in my project i have one module and one form on the form i have one label and one button, and on the module i have...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.