Solved

Call a function where function name is a string

Posted on 2002-03-25
7
341 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

706 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

14 Experts available now in Live!

Get 1:1 Help Now