Execute a VB Code from a string statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KleberUK
    New Member
    • Apr 2010
    • 5

    Execute a VB Code from a string statement

    Hello again,

    I've got an issue. I would like to be able to execute a specific piece of VB code from a string statement.

    Let me explain. For instance, I know it's possible to run a SQL statement by using the command:

    DoCmd.RunSQL STRING_SQL

    Is it possible to do something similar, but not using SQL statements? For instance, is it possible to change the form title by using a Run command???

    For example:
    STRING_CODE="Me .Caption=" & Chr(34) & "My Form" & Chr(34)

    DoCmd.??? STRING_CODE

    Please let me know if you need more information.

    Thanks in advance!
  • vb5prgrmr
    Recognized Expert Contributor
    • Oct 2009
    • 305

    #2
    There are a couple of ways in which to do this but the way you describe, no.

    If shelling out another exe you would use the command object in that shelled exe to read the command line parameters and take action upon those parameters and changing the caption of a form is a possibility.

    If you create an activex exe and expose that property it would be possible to control it from another exe.

    Now, if you are wanting to allow the user to change the caption of the current form, I would suggest an options dialog and allow the user to enter the caption>hit apply/ok and you change the caption of the form to the text entered else if no text, display default caption. You could also probably do this using an input box or even a control on the form but you will have to parse this if you want to control multiple properties. For example...

    Users enters
    Caption=Test

    You would then have to parse out the caption part of the text and the text to change the caption to...
    Code:
    Private Sub Command1_Click()
    Dim MyArray() As String
    MyArray = Split(Text1.Text, "=")
    Select Case MyArray(0)
    Case "Caption"
      Me.Caption = MyArray(1)
    Case "Left
      '....
    End Select
    End Sub

    Good Luck

    Comment

    • KleberUK
      New Member
      • Apr 2010
      • 5

      #3
      Hello!

      Thanks for you reply. You definitely understood what I meant.

      However, I would not want the user to change the caption of the form himself.

      For instance,

      Instead of having this code:

      Private Sub Form_Open(Cance l As Integer)

      Me.Caption = "My Form"
      Me.AutoCenter = True

      End Sub

      I would like to do:

      Private Sub Form_Open(Cance l As Integer)

      Dim string_Caption As String
      Dim string_AutoCent er As String

      string_Caption = "Me.Caption =" & Chr(34) & "My Form" & Chr(34)
      string_AutoCent er = "Me.AutoCen ter = True"



      End Sub

      Comment

      • KleberUK
        New Member
        • Apr 2010
        • 5

        #4
        Sorry I clicked send but I hadn't finished.

        So I would like run a command to run those two strings

        Run string_Caption
        Run string_AutoCent er

        And access would interpret that and run the Me.Caption and Me.AutoCenter properties.

        Thanks again.

        Comment

        Working...