Solved

Writing code at runtime

Posted on 2001-06-07
5
150 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:xSinbad
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:wpsjr1
ID: 6166237
Use the MS Scripting Control, its accessable in VB at least.  You would add code using visual basic script.
0
 
LVL 5

Expert Comment

by:aminerd
ID: 6166377
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
 
LVL 5

Accepted Solution

by:
aminerd earned 10 total points
ID: 6166380
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
 
LVL 6

Author Comment

by:xSinbad
ID: 6166392
Thanks wpsjr1 and aminerd I will check that out tonight.

Cheers
Marcus
0
 
LVL 6

Author Comment

by:xSinbad
ID: 6179351
Thanks for the extra info aminerd.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question