Storing code in a String Variable

  • Thread starter Thread starter Allen Browne
  • Start date Start date
Hi;
For some reason,i need to put a part of code in a string variable and then
run this code.The main purpose of this work is to store this code part in a
table,and when needed,read that record of table and store it in a string
variable,then run this code from inside the variable.So i can remotly update
that table and change that code part as i want.We can do this with the SQL
statements easily,but about VBA code im not sure.Is it possible?
Thank you in advance.
 
Thank you;
How to use Eval() function here?
Suppose i want to show a MsgBox:

Dim StrCode as String
strCode = "msgbox 'Hi'"
Y=Eval (strCode)

But this wont work.I feel i need a RunCode Command here.Can you help me?
Thanks a lot.
 
RunCode accepts the name of a function to be run. Off the top of my head, I
can't think of a way to execute a string like that.

A fairly ridiculous work around might be to open a form in design view
(hidden), assign the string to the form's On Close property, close it, open
it in form view (but hidden) and then close it. The Close event would
trigger the code. Did not have to be that event, but you get the idea.
 
Ok,Thank you.

Allen Browne said:
RunCode accepts the name of a function to be run. Off the top of my head, I
can't think of a way to execute a string like that.

A fairly ridiculous work around might be to open a form in design view
(hidden), assign the string to the form's On Close property, close it, open
it in form view (but hidden) and then close it. The Close event would
trigger the code. Did not have to be that event, but you get the idea.
 
Back
Top