Solved

Call a function where function name is a string

Posted on 2002-03-25
7
343 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

831 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