Storing code in a String Variable

M

Mota

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.
 
M

Mota

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.
 
A

Allen Browne

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.
 
M

Mota

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top