Solved

Writing code at runtime

Posted on 2001-06-07
5
154 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

733 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