Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How execute code when code is in a textbox. 1

Status
Not open for further replies.

Accel45

Technical User
Jul 7, 2004
83
0
0
US
BACKGROUND:
I find myself creating help message boxes frequently so I put together a DB to help with creating the string for the msgbox. I enter the steps or instructions into a continuous form:

How To Eat A Banana
First, Remove the Peel
Second, Open Mouth
Third, Shove Banana in Mouth

The result is a piece of code produced in a textbox that I can copy and used with a command button:

Dim strHelp As String
Dim crlf As String
crlf = Chr$(13) & Chr$(10)
strHelp = "How To Eat A Banana" & crlf & crlf
strHelp = strHelp & "First, Remove the Peel" & crlf
strHelp = strHelp & "Second, Open Mouth" & crlf
strHelp = strHelp & "Third, Shove Banana In Mouth" & crlf
MsgBox (strHelp)

The process is working fine as described and the code functions properly when used on the On Click of a command button.

MY QUESTION:
I would like to execute the code in the textbox to check the formatting of the msgbox before copying and pasting it into another DB. How do I execute the code in the textbox without having to place the code on the On Click of a command button.

Private Sub cmdHelpMessage_Click()
“Some Code to execute what appears in [textbox]
End Sub

Any help will be appreciated.
 
Here's one way:

Code:
[blue][green]' requires a reference to Micosoft Visual Basic for Applications Extensibility[/green]
Dim myCodeModule As VBComponent
Set myCodeModule = Application.VBE.ActiveVBProject.VBComponents.Add(vbext_ct_StdModule) '.CodeModule.AddFromString "'Rem"
myCodeModule.CodeModule.AddFromString "Public function DoTest" & vbCrLf & TextBox1.Text & vbCrLf & "End function"
Eval "DoTest()"
Application.VBE.ActiveVBProject.VBComponents.Remove myCodeModule[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top