Closed Thread
Results 1 to 3 of 3

Using The Text From A Textbox In A UserForm

  1. #1
    Donna
    Guest

    Using The Text From A Textbox In A UserForm

    I think I have broken the back of programming OptionBoxes and
    ComboBoxes in userforms but am trying to use the text entered into a
    textbox. I have the text box to initially show "x" but want the user
    to change this and then save it to a variable. I can get round this
    by using the .controlsource referncing a cell but want to use a
    variable instead. This is my code:-

    Dim Tempform
    Public NewTextBox As MSForms.TextBox ' In Declarations
    Public c as String ' In Declarations
    Dim X As Integer

    Set Tempform=ThisWorkbook.VBProject.VBComponents.Add(3)
    Set NewTextBox=TempForm.Designer.Controls.Add("forms.TextBox.1")
    With NewTextBox
    .text="x"
    End With

    Set NewCommandButton1=.........("forms.CommandButton.1")

    With Tempform.CodeModule
    X = .CountOfLines
    .InsertLines X + 1, "Sub CommandButton1_Click"
    .InsertLines X + 2, " c=NewTextbox.Text"
    .InsertLines X + 3, " Unload Me"
    .InsertLines X + 4, "End Sub"
    End With

    This always gives me c="x". Can anybody tell me what I am doing
    wrong?
    Thanks, as always!

  2. #2

    Re: Using The Text From A Textbox In A UserForm

    As an addition to the above I do show the form using
    VBA.UserForms.Add(Tempform.Name).Show


  3. #3

    Re: Using The Text From A Textbox In A UserForm

    As usual..post a question and then immediately sort it out!
    .InsertLines X + 2, " c=Textbox1.value"
    works!


Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1