Writing code at runtime

This is in the Access section but is appropriate for this area as well.

http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=msaccess&qid=20131698
LVL 6
xSinbadAsked:
Who is Participating?
 
aminerdConnect With a Mentor Commented:
You can also allow the code to access objects in your program by using the AddObject method...

Sub RunCode()
 
  Dim strCode As String
  strCode = "frmMain.lblHi.Caption=""Hello!"""
 
  Dim objScript As ScriptControl
  Set objScript = New ScriptControl
 
  'Assuming this sub is in a form with a label called lblHi
  Call objScript.AddObject("frmMain", Me, True)
  Call objScript.Execute(strCode)
 
  Set objScript = Nothing
 
End Sub
0
 
wpsjr1Commented:
Use the MS Scripting Control, its accessable in VB at least.  You would add code using visual basic script.
0
 
aminerdCommented:
xSinbad,

Check out the Microsoft Scripting Control. With it you can execute code at runtime. For instance (in VB):

Sub RunCode()
 
  Dim strCode As String
  strCode = "Call MsgBox(""Hello!"")"
 
  Dim objScript As ScriptControl
  Set objScript = New ScriptControl
 
  'A message box will pop up
  Call objScript.Execute(strCode)
 
  Set objScript = Nothing
 
End Sub
0
 
xSinbadAuthor Commented:
Thanks wpsjr1 and aminerd I will check that out tonight.

Cheers
Marcus
0
 
xSinbadAuthor Commented:
Thanks for the extra info aminerd.
0
All Courses

From novice to tech pro — start learning today.