none
Userform checkbox to insert text from textbox RRS feed

  • Question

  • I apologize if this is a really basic question, but I am very new at this and learning as I go. For our office, I am creating a userform in Word 2010 that will be used on multiple documents. The userform has a series of checkboxes and textbox controls. When the checkboxes are checked, it enters text into the word document. For some of the checkboxes, I also need it to enter the information that is entered into the textbox right below it. I am able to get the checkboxes to work, but I cannot figure out how to enter the information from the textbox when the checkbox is checked.

    Here is the code that I have so far for this section:

     

    Private Sub CheckBox16_Click()
    If CheckBox16.Value = True Then
    Selection.TypeParagraph
    Selection.TypeText Text:="Avoid all contact with the following named persons:"
    Selection.InsertAfter Text:=TextBox1.Text
    End If
    End Sub
    
    Private Sub TextBox1_Change()
    TextBox1.Value = TextBox1.Text
    End Sub
    
    Private Sub CommandButton1_Click()
    Unload Me
    End Sub
    

    I would really appreciate it if someone could help guide me in the right direction as to what is the correct way to accomplish this.

    Thursday, September 8, 2011 11:43 PM

Answers

  • Use

    Private Sub CommandButton1_Click()
    If CheckBox16.Value = True Then
        Selection.Range.InsertAfter vbCr & "Avoid all contact with the following named persons: " & TextBox1.Text
    End If
    Me.Hide
    
    Unload Me End Sub

    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    • Proposed as answer by Liliane Teng Thursday, September 15, 2011 8:28 AM
    • Marked as answer by Liliane Teng Thursday, September 15, 2011 8:28 AM
    Friday, September 9, 2011 8:14 AM

All replies

  • Use

    Private Sub CommandButton1_Click()
    If CheckBox16.Value = True Then
        Selection.Range.InsertAfter vbCr & "Avoid all contact with the following named persons: " & TextBox1.Text
    End If
    Me.Hide
    
    Unload Me End Sub

    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    • Proposed as answer by Liliane Teng Thursday, September 15, 2011 8:28 AM
    • Marked as answer by Liliane Teng Thursday, September 15, 2011 8:28 AM
    Friday, September 9, 2011 8:14 AM
  • I think that worked! Thank you so much!
    Wednesday, September 21, 2011 5:49 PM