Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / July 2007

Tip: Looking for answers? Try searching our database.

Method of calling a function where function name is stored in a variable or control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tony Vrolyk - 11 Jul 2007 20:34 GMT
(This is a repost of a posting in microsoft.public.access which was an
accident, sorry)

Is there a way to call a function (or sub for that matter) where the
function/sub name is stored in a variable?

For instance lets say I have a table that stores some function names. On a
form I have a list box that displays the records in that table. For this
example lets say they all accomplish similar things and all require the same
numbef of arguments and none of them return a value.

If Call were the right method to accomplis this it might look sometihng like
this

   Dim lngArgument as Long
   lngArgument = 1234

   Call Me.lstBox, lngArgument

In this case Call would run the function whose name is currently the
selected value in Me.lstbox.

Is such a thing possible? I am using Access 2002.

thanks
Tony Vrolyk
John Spencer - 11 Jul 2007 21:02 GMT
Take a look at the EVAL function, you can use it with functions

For instance

Eval("fGetOrdinal(234)")

So with your example, if the value in lstBox was the name of a public
function in a module this MIGHT work for you
EVAL(me.lstbox & "(" & lngArgument & ")")

Signature

John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
.

> (This is a repost of a posting in microsoft.public.access which was an
> accident, sorry)
[quoted text clipped - 24 lines]
> thanks
> Tony Vrolyk
Tony Vrolyk - 11 Jul 2007 21:10 GMT
You are beautiful person. I tried posting about this quite a while back and
no one who responde could quite help me. I did try the EVAL function but had
my syntax wrong. i was trying to do it without the parenthesis.

I just tested it and it works. that will make life so much easier.

thanks
Tony

> Take a look at the EVAL function, you can use it with functions
>
[quoted text clipped - 35 lines]
>> thanks
>> Tony Vrolyk
Klatuu - 11 Jul 2007 22:14 GMT
I'm glad I am not the one who will have to debug that code.
Signature

Dave Hargis, Microsoft Access MVP

> You are beautiful person. I tried posting about this quite a while back and
> no one who responde could quite help me. I did try the EVAL function but had
[quoted text clipped - 44 lines]
> >> thanks
> >> Tony Vrolyk
John Spencer - 12 Jul 2007 00:34 GMT
Amen to that.

'====================================================
 John Spencer
 Access MVP 2002-2005, 2007
 Center for Health Program Development and Management
 University of Maryland Baltimore County
'====================================================

> I'm glad I am not the one who will have to debug that code.
Tony Vrolyk - 12 Jul 2007 17:57 GMT
Now I am curious why  you say that. If you meant to imply that my coding in
general must be bad if I fogot the parenthesis - I did not mean the ones
required by the EVal funtion but rather the ones required by the function
within the Eval.

   i.e.
   EVAL(me.lstbox & "(" & lngArgument & ")")

   vs
   EVAL(me.lstbox lngArgument)

Before the Eval I called them like this
   fFunctionName Argument1

Having not used the Eval before I assumed that within the Eval you would
call a function the same way you would outside the Eval. In this case these
functions do not require the parnethesis when run on their own. So I don't
think that is an unreasonable assumption.

Tony

> I'm glad I am not the one who will have to debug that code.
>
[quoted text clipped - 52 lines]
>> >> thanks
>> >> Tony Vrolyk
Tony Vrolyk - 12 Jul 2007 18:05 GMT
Sorry - my sent items only shows one, not sure what happened there.

> Now I am curious why  you say that. If you meant to imply that my coding
> in general must be bad if I fogot the parenthesis - I did not mean the
[quoted text clipped - 74 lines]
>>> >> thanks
>>> >> Tony Vrolyk
John Spencer - 12 Jul 2007 19:13 GMT
No, I wasn't being critical of your coding.  What I meant was that debugging
code that has a problem is difficult enough without having to work out which
function was being called depending on which string was in the field could
be tough.

I have actually used a similar technique to handle some complex importation
of legacy data that had to be manipulated different ways depending on the
year of the data file and the field name of the data itself.  Long Story -
and it was difficult to debug and I had written the code and was very
familar with what was supposed to happen.

Signature

John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
.

> Now I am curious why  you say that. If you meant to imply that my coding
> in general must be bad if I fogot the parenthesis - I did not mean the
[quoted text clipped - 74 lines]
>>> >> thanks
>>> >> Tony Vrolyk
Tony Vrolyk - 12 Jul 2007 19:20 GMT
Gotcha. Sorry to be so sensative.

I think in this case it will be relatively easy. I am keeping as much
similarity between the functions called by the Eval as possible - same
number of arguments, same argument types, etc..

Thanks again
tony

> No, I wasn't being critical of your coding.  What I meant was that
> debugging code that has a problem is difficult enough without having to
[quoted text clipped - 85 lines]
>>>> >> thanks
>>>> >> Tony Vrolyk
Tony Vrolyk - 12 Jul 2007 17:58 GMT
Now I am curious why  you say that. If you meant to imply that my coding in
general must be bad if I fogot the parenthesis - I did not mean the ones
required by the EVal funtion but rather the ones required by the function
within the Eval.

   i.e.
   EVAL(me.lstbox & "(" & lngArgument & ")")

   vs
   EVAL(me.lstbox lngArgument)

Before the Eval I called them like this
   fFunctionName Argument1

Having not used the Eval before I assumed that within the Eval you would
call a function the same way you would outside the Eval. In this case these
functions do not require the parnethesis when run on their own. So I don't
think that is an unreasonable assumption.

Tony

> I'm glad I am not the one who will have to debug that code.
>
[quoted text clipped - 52 lines]
>> >> thanks
>> >> Tony Vrolyk
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.