Solved

Call a function where function name is a string

Posted on 2002-03-25
7
347 Views
Last Modified: 2008-03-10
I want to be able to call functions.  The names are stored in a table.  I am looking up the name in the table using a dlookup.  When I get the name of the function, I try to call the function but it does not work.  I am using the Eval Function.  Code looks like this

dim strProgramCall as string

strProgramCall = Nz(DLookup("[ProgramCall]", "Report List", "[Report ID] = " & Me.Selected_Report), "None")
Eval(strProgramCall)

Error message says Run-time Error 2482 Clone Can't find the name 'NameOfFunction' you entered in the expression.

Yes, there is a function that is called NameOfFunction.  

Can I call a function this way?  What am I doing wrong?
0
Comment
Question by:LJ083198
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 2

Expert Comment

by:xtrahands
ID: 6895599
LJ

I don't have the answer but I do know what the problem is.

When you evaluate the function NameOfFunction the syntax is eval(NameOfFunction) not eval("NameOfFunction")

I tried to do something similar a while back but never managed to find the answer so good luck.

xtrahands
0
 
LVL 2

Expert Comment

by:xtrahands
ID: 6895608
LJ

I don't have the answer but I do know what the problem is.

When you evaluate the function NameOfFunction the syntax is eval(NameOfFunction) not eval("NameOfFunction")

I tried to do something similar a while back but never managed to find the answer so good luck.

xtrahands
0
 
LVL 2

Accepted Solution

by:
xtrahands earned 100 total points
ID: 6895609
LJ

I had another look at that database and I did get it to work.  My syntax was:

     If strProgramCall <> "" Then
        varX = Eval(strProgramCall & "()")
     End If

Give it a crack and see if it works.

xtrahands


0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:Syed Irtaza Ali
ID: 6895816
Well there is a way but for that u will need a form from where you want to call the function.

You will be using the OnTimer event and TimerInterval property for that form.

the code is

get the function name then

Form1.onTimer = "=" & strFunctionName & "()"
Form1.TimerInterval=1000 ''''' ie for 1 sec


try it and if u have any problem do mention.

Nomi.
0
 
LVL 2

Expert Comment

by:Syed Irtaza Ali
ID: 6895830
Give xtrahands the points. It damn works!
0
 
LVL 11

Expert Comment

by:joekendall
ID: 6896202
Here is a link that backs up what xtrahands wrote.

http://www.mvps.org/access/modules/mdl0002.htm

Thanks!

Joe
0
 

Author Comment

by:LJ083198
ID: 6897692
YOU ARE AWESOME
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question