Solved

Call a function where function name is a string

Posted on 2002-03-25
7
342 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
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

867 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now