Runtime code generation

  • Thread starter Thread starter Shawn Wesley
  • Start date Start date
S

Shawn Wesley

I would like to run a procedure specified in a field of a
recordset. For example, say I wanted a specific routine
to be used to process each record of a table. Today I
only need 4 routines to handle all my records, but I
foresee needing many more. I could put a number field in
the table which would drive a Select CASE statement to
run the specific routine I needed, but whenever I needed
a new routine, I would have to create the new routine AND
edit the Select CASE statement to handle the new id. It
would be great if I could just have a text field in the
table that told the processing routine which subroutine
to run. That way I could just add the new routine and
everything else would run as is. Is there anyway to
generate code commands at runtime?

Thanks...
 
You can "run" a rotine you speiclfy at runtime via:

strFunc = inputbox("what function to run")

eval(strFunc)

The above lets you prompt a user as to what function to run.

You need to include the () for the function name. So,

strFunc = "MyCoolFunciton()"

Eval (strFunc)
 
Shawn said:
I would like to run a procedure specified in a field of a
recordset. For example, say I wanted a specific routine
to be used to process each record of a table. Today I
only need 4 routines to handle all my records, but I
foresee needing many more. I could put a number field in
the table which would drive a Select CASE statement to
run the specific routine I needed, but whenever I needed
a new routine, I would have to create the new routine AND
edit the Select CASE statement to handle the new id. It
would be great if I could just have a text field in the
table that told the processing routine which subroutine
to run. That way I could just add the new routine and
everything else would run as is. Is there anyway to
generate code commands at runtime?


If you make the procedures Public Functions in a standard
module, then you can use the Eval function to execute the
function.

Another possibility is to use the Run method.

Check Help for details to see if either of those fit your
needs.
 
Back
Top