Solved

Writing code at runtime

Posted on 2001-06-07
5
145 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now