Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Variables to Store Method Names

Status
Not open for further replies.

Sameal

Programmer
Aug 6, 2001
142
US
I have an array with 8 elements. Each element holds a string which is the name of a particular method. I'm wanting to run through all 8 elements running each method in order to produce my results. After building the array I tried to call the methods:

ModuleName.MyArray(i)

I got an error stating that a name of a procedure was expected rather then a variable. Is there any way to call a method or function by using a variable for it's name?
 
Hi!

As far as I know you can't do that without defining your own object with it's own methods and properties. It seems that it would be easier to just code the methods in order rather than going to that much trouble, unless it is something that you will need in other databases.

Jeff Bridgham
 
try
DoCmd.RunCode "......." & functionNameVariable & "(" & "arguments" & ")" John Fill
1c.bmp


ivfmd@mail.md
 
I can't find a method named RunCode of the DoCmd object. Do I need to add some additional refrences to the the VBA environment to use this? Or were you thinking of the DoCmd.RunCommand method?
 
Hi!

The RunCode Action is available to macros. Since there are much easier ways to call functions from code it isn't part of the DoCmd object. But you can use you loop in a similar way.

For i = 1 To 8
Call ProcedureName(i)
Next i

Then in the procedure put a select statment.

Select Case i
Case 1
ModuleName.FirstMethod
Case 2
etc.

I am not sure if you will gain any functionality this way.

hth
Jeff Bridgham
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top