473,725 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Eval Function - Recursive call?? Routine Being Called Multiple Times

4 New Member
Hi there

I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with or without parms. I know that any function that is passed to Eval() must be declared Public. It can be a Sub or Function, as long as it's Public. I even have it where the "function" evaluated by Eval can be in a form (class) module or in a standard code module (and if in a form module, as long as the call is fully qualified, I can call it). That's all good.That's not the problem. The problem is with the # of times my routine that houses my Eval function call is run by Access.

I have done some research on this, but it appears that those out there having the same problem have never really gotten a good answer to/reason for this problem (just some work arounds I imagine)

Research Links:
Here problem did get a resolution, but Dirk's post shows that he was having problems with the function being called twice too:

http://awomantoldme.co m/women/how-to/31178849/why-does-this-code-not-wo.aspx

Same posting: http://www.microsoft.com/communities...325a8633e8&p=1

And there was another older posting I've seemed to have lost the link to where the poster was having the same recursive call problem, but there were no responses ever posted ;-(

SCENARIO
=========


I have a Main Form (frmMain) containing 2 subforms (fsubChild1 and fsubChild2).

The SourceObject value for fsubChild2 is constantly being changed to show whatever form I am working on at the time (think of frmMain as simply a container form for my 2 subforms and really does nothing more and has no other controls on it, other than an Exit Application button)

fsubChild1 contains labels, that, when clicked on, excutes a standard function that must exist in the code-behind-form for any valid form that can be plugged in as the SourceObject for fsubChild2. Let's call this standard function mtdRunTheCode. It exists as a PUBLIC function in every form that could potentially be the SourceObject for fsubChild2 and is passed the name of a function to execute, depending on the label clicked in fsubChild1 (each label in fsubChild1 passes mtdRunTheCode a different function. Think of mtdRunTheCode() as a wrapper function. It always contains the Eval(strFunctio n) code line, but may also contain code or calls to other routines specific to the form in which it is executing. I wanted to do this so that fsubChild1 could call generic functions (located in a standard code module) that must be run when a label is clicked (no matter what form is contained in fsubChild2), but, depending on the form in fsubChild2, can run code specific to fsubChild2 first (such as validating the current record, saving, etc etc)

Let's imagine that I had 2 forms: frmCust and frmProd.

Both of these forms at any given time, could be the SourceObject for fsubChild2
Both of these forms contain their own version of mtdRunTheCode - declared Public, named the same and located in the subform's form module (ie the function becomes a "method" of the form)..

This is how the function looks in frmCust

Expand|Select|Wrap|Line Numbers
  1. Public Function mtdRunTheCode(strFunction)
  2.    'This function is called by the OnClick event of a given label in fsubChild1
  3.    'The value of strFunction changes, depending on the label that was clicked
  4.    'and contains the name of a unique, public function to execute. All of these
  5.   ' public functions are contained in a single Code Module.
  6.  
  7.    'Code that is specific to this form
  8.    Application.RunCommand acCmdSaveRecord
  9.  
  10.    'Execute the general function passed in by clicking a label in fsubChild1
  11.    Eval(strFunction)
  12.  
  13. End Function
  14.  
And this is how that same function it looks in frmProd
Expand|Select|Wrap|Line Numbers
  1. Public Function mtdRunTheCode(strFunction)
  2.    'This function is called by the OnClick event of a given label in fsubChild1
  3.    'The value of strFunction changes, depending on the label that was clicked
  4.    'and contains the name of a unique, public function to execute. All of these
  5.   ' public functions are contained in a single Code Module.
  6.  
  7.    'Code that is specific to this form
  8.    DoCmd.OpenReport "rptSomeName"
  9.    etc
  10.  
  11.    'Execute the function passed in by clicking a label in fsubChild1
  12.    Eval(strFunction)
  13.  
  14. End Function
  15.  
The Calling Code in fsubChild1

Expand|Select|Wrap|Line Numbers
  1. Private Sub lblTask1_Click()
  2.  
  3.   Call Forms!frmMain!fsubChild2.mtdRunTheCode("udfGeneralFunc()")
  4.  
  5. End Sub
  6.  
  7. Private Sub lblTask2_Click()
  8.  
  9.   Call Forms!frmMain!fsubChild2.mtdRunTheCode("udfAnotherFunc()")
  10.  
  11. End Sub
  12.  
  13.  
And finally, the generic function located in it's own standard code module
Expand|Select|Wrap|Line Numbers
  1. Public Function udfGeneralFunc() As Boolean
  2.  
  3.   MsgBox "This is nifty stuff"
  4.  
  5. End Function
  6.  
By doing the above, I can utilize the same general functions for an OnClick of a lable, no matter what subform is in fsubChild2, yet execute form specific code first, if needed.

THE PROBLEM
============
I don't get errors if I try to run Eval routine in any of the the mtdRunTheCode() routines. What happens is that the mtdRunTheCode routine runs TWICE. I tracked it and when I click the label in fsubChild1, the following events occur:

- Calls mtdRunTheCode
- Executes the Eval function (which in turns calls the passed in function located in a code module)
- Recursively calls mtdRunTheCode again
- Re-executes the Eval function again.

So for example, if the strFunction arg passed to mtdRunTheCode was a call to the public function udfOpenTheForm( 'frmTest'), and udfOpenTheForm simply ran the openform command to open the frmTest form (in Normal Window mode), this is what happens

- Calls mtdRunTheCode
- Executes the Eval function (calls udfOpenTheForm which opens the frmTest form)
- Recursively calls mtdRunTheCodeag ain
- Re-executes the Eval function again (recalls udfOpenTheForm)

If udfOpenTheForm opens the form in dialog mode, since that halts execution until the form is closed, it causes different problems, making the user click twice to close that form ->

- Calls mtdRunTheCode
- Executes the Eval function (calls udfOpenTheForm which opens the frmTest form in acDialog mode). Waits until user closes form.
- Recursively calls mtdRunTheCode again
- Re-executes the Eval function again (recalls udfOpenTheForm)
- waits until user closes the form, then finally leaves the mtdRunTheCode routine


I don't really want to put the mtdRunTheCode() in a standard code module, because I really want to be able to execute form specific things before executing the code resulting from a label's onclick event (and I may not want to do that for a different form)

Does anyone know the reason for the recursive call?? I've been struggling with this for a bit now and it's driving me nuts.

Thanks!
RandomElle
Dec 29 '07 #1
6 5927
ADezii
8,834 Recognized Expert Expert
Hello RandomElle. In my humble opinion, you will be struggling for a long, long time to come if you continue with your current approach:
  1. The 'Public' to which you refer as a requirement for evaluating Functions with Eval(), refers to Standard Code Modules, not Form Modules. A Public Function, or for that matter Sub-Routine, in a Form's Class Module becomes a Method of the Form and is technically no longer a Function or Sub-Routine. You make this point yourself in your calls.
    Expand|Select|Wrap|Line Numbers
    1. Call Forms!frmMain!fsubChild2.mtdRunTheCode("udfAnotherFunc()")
    You are not calling a Function, but executing the mtdRunTheCode Method of fSubChild2. Since when does a Function/Sub-Routine Call have a Dot (.) qualifier?
  2. Having Functions/Sub-Routines with the same Names, even when differentiated by Scope, is seldom a good idea.
  3. In the short amount of time that I had to look over your problem, I feel as though either 1 or both of the above listed points are contributing to your duplication problem, and I truly believe that if you continue with the current logic, there will be more problems down the road. Good Luck!
  4. It would also be a good idea to wait and see what some of the other Experts/Moderators/Members have to say on the Subject.
Dec 30 '07 #2
FishVal
2,653 Recognized Expert Specialist
Hi, there.

Couldn't reproduce the error. In the attached example form's method runs once as expected.

Regards,
Fish

P.S.
Having Functions/Sub-Routines with the same Names, even when differentiated by Scope, is seldom a good idea
Are you superstitious? ;)
Attached Files
File Type: zip DupCall.zip (14.5 KB, 165 views)
Dec 30 '07 #3
ADezii
8,834 Recognized Expert Expert
Hi, there.

Couldn't reproduce the error. In the attached example form's method runs once as expected.

Regards,
Fish

P.S.

Are you superstitious? ;)
Hello Fish, sorry, but I seem to be very slow today.
Are you superstitious?
What does the reference mean?

P.S. - Have a Happy New Year!
Dec 30 '07 #4
FishVal
2,653 Recognized Expert Specialist
Hello Fish, sorry, but I seem to be very slow today.

What does the reference mean?

P.S. - Have a Happy New Year!
Hello, ADezii.

That was just a joke relating to:
  1. .....
  2. Having Functions/Sub-Routines with the same Names, even when differentiated by Scope, is seldom a good idea.
  3. .....
  4. .....
It seems to me a bit overkill to provide unique names for methods of different classes. I'm almost sure there is nothing unsafe in it. For example, many classes have property "Name".

I think the source of the fault is somewhere beyond the details provided by OP.

Best regards and have a Happy New Year!

Fish
Dec 30 '07 #5
ADezii
8,834 Recognized Expert Expert
Hello, ADezii.

That was just a joke relating to:

It seems to me a bit overkill to provide unique names for methods of different classes. I'm almost sure there is nothing unsafe in it. For example, many classes have property "Name".

I think the source of the fault is somewhere beyond the details provided by OP.

Best regards and have a Happy New Year!

Fish
Gottcha! See ya next year! (LOL).
Dec 30 '07 #6
I was having a similar issue in Excel 2007 when trying to dynamically call a procedure. My code basically looked like:

Application.Run Range("A1").Val ue

where cell A1.value = "someproc() "

I found that when the parenthesis were included the procedure would end up being called twice. After changing the value of A1 to "someproc" the procedure was only called once.
Sep 30 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2888
by: | last post by:
OK: Purpose: Using user's input and 3 recursive functions, construct an hour glass figure. Main can only have user input, loops and function calls. Recursive function 1 takes input and displays a sequence of spaces; recursive function 2 uses input to display ascending sequence of digits; likewise, recursive function 3 uses input to display descending sequence of digits. I have not followed the instructions completely regarding the...
9
8334
by: Paul | last post by:
I'm trying to make get my app to delete all the files in a specified folder and all the files within the folders of the specified folder. e.g. Folder 1 contains three files (File1, File2, File3) and two folders (Subfolder 1, Subfolder 2). .......I need to delete File1, File2, File3. Subfolder 1 contains FileA. .......Need to delete FileA. Subfolder 2 contains FileB, FileC, FileD.
5
1922
by: Peri | last post by:
Dear All, In VB 6.0 declaring this function and calling this functions works smoothly. But in VB.NET or ASP.NET (Code behind), I am getting an error in the line "HResult = CreateReportOnRuntimeDS(Rs, svReportFile, svTTXFile, False, True)" saying that, "Object reference not set to an instance of an object." Can any one help me out to solve this problem. Module Report Declare Function CreateReportOnRuntimeDS Lib "p2smon.dll" (ByVal
23
7813
by: bluejack | last post by:
Ahoy... before I go off scouring particular platforms for specialized answers, I thought I would see if there is a portable C answer to this question: I want a function pointer that, when called, can be a genuine no-op. Consider: typedef int(*polymorphic_func)(int param);
4
2364
by: Michael | last post by:
Hi, I'm having difficulty finding any previous discussion on this -- I keep finding people either having problems calling os.exec(lepev), or with using python's exec statement. Neither of which I mean here. Just for a moment, let's just take one definition for one of the
8
1505
by: rdrink | last post by:
n.n.h. (noob needs help) Ok, I've been beating my head against this for a day... time to ask others. To explain things as simply as possible: I am trying to use eval() to evaluate some simple equations, such as-- pow(AB,2) pow(AB,2)+A pow(A+B,2) pow(A+B,2)+A and so forth... for a variety of math operations (+,-,*) and a variety
7
2109
by: =?Utf-8?B?RGF2aWQgQ29sbGl2ZXI=?= | last post by:
Hi all, using C#, .NET 1.1, ASP.NET I have created a recursive??? function. It looks a little like... MyContext.Current.Folder.Parent.Parent.Parent.Parent.Name As you can see, Parent is the recursive??? part.
6
3631
by: vasudevram | last post by:
Hi group, Question: Do eval() and exec not accept a function definition? (like 'def foo: pass) ? I wrote a function to generate other functions using something like eval("def foo: ....") but it gave a syntax error ("Invalid syntax") with caret pointing to the 'd' of the def keyword.
9
2635
by: pereges | last post by:
Hello I need some ideas for designing a recursive function for my ray tracing program. The idea behind ray tracing is to follow the electromagnetic rays from the source, as they hit the object.The object is triangulated. The rays can undergo multiple reflections, diffractions etc of the same object i.e. a ray hits a surface of the object, undergoes reflection resulting in a reflected ray which can again hit a surface, corner or edge...
0
8888
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9401
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9176
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9113
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8097
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.