473,574 Members | 2,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_SubRou tineCall", 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 CallObjectModul e As Module
Set CallObjectModul e = Modules("My Module")
CallByName CallObjectModul e, "My_Module_SubR outineCall", VbMethod

Thanks for any ideas!

Nov 13 '05 #1
5 12092
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_SubRou tineCall", 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 CallObjectModul e As Module
Set CallObjectModul e = Modules("My Module")
CallByName CallObjectModul e, "My_Module_SubR outineCall", 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.Func tionName <(params)>

Sub:

ModuleName.SubN ame <params>

<> indicates optional.

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

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

iQA/AwUBQnaAMIechKq OuFEgEQIUPACgly BLh4vliGCrH/UAytT593WG6gMAn AwV
jN/QDY0Xd9kOe4BKpv cjbTkF
=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(strProcedu re)

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.Rout ineName

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

E.g.:

intRound = Math.Round(dblP ercentage,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:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQnaTlYechKq OuFEgEQIWvgCg5o EpVAnJXqzchsWDa JtnN2XvlSQAoLOd
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
1898
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 errors. Can anyone help?
9
3000
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 As Long)
3
5661
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 to read the Form or Module text itself. I am able to locate, then connect to the databases, and have figured out how to get the Form and Module names easy enough using the documents collection of...
2
1389
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 standard module? Thanks! Judy
4
13892
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
1772
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 send an object into the module function and then I try to change a chart title and then the function return a chart object with the change of chart title. I don`t know how to set the reference from...
2
1777
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 has keys for the various named elements *within* the form... I could easily replicate the form name in a hidden field, but there ought to be some way to get directly at the form name but I'm just...
1
1749
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), "items.add", Type.Set, "2nd item") CallByName(Form1.Controls("ComboBox" & i), "items.add", Type.Set, "3rd item") next Is there a way I can populate these 3 combo boxes using the CallByName feature. My...
2
1078
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 a sub called callme() -> wich display a text mesasage on the form when i press the button the sub is called and the label is populate this is what i want to do, but i don't know where i go wrong ...
0
7813
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8066
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7826
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8106
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6461
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5631
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3755
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2251
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1350
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.