locked
How to add a paragraph when a user checks a control box RRS feed

  • Question

  • Hi,

    I have a word 2010 document consisting of a questionnaire in the beginning and a form letter at the end. One section of the questionnaire only applies to certain people. If this section does not apply to the user, I want to hide (or remove) text from the form letter. If it does apply, I want to add (or insert) text into the form letter.  I want to place a checkbox at the beginning of that section in the questionnaire which would either add or hide text in the form letter.

    How would I go about doing that?

    I uploaded an example Word doc here: https://docs.google.com/open?id=0ByDhIYEdFQPGamVBdWtFblRTOXc

    If you download it and open it in Word, you'll see the comments that I added. There are no macro's in this doc.

    Wednesday, May 16, 2012 10:37 AM

Answers

  • I solved my own question. For anyone who wants to know, here's the solution:

    First off, there are 3 different kinds of checkboxes in Word 2010. In the Developer section of the ribbon (you may have to add it), there's Check Box Content Control. Also in the same section of the ribbon, there a Legacy Tools icon that contains two more checkboxes. Under Legacy Forms, there's a Check Box Form Field, and under ActiveX Controls there's a Check Box (ActiveX Control). After messing around with all 3, I was only able to get the Check Box (ActiveX Control) to work.

    Step 1: Place the Check Box (ActiveX Control) into your document. Right-click on the control and select properties to change the name, caption, color, or anything else for the control. I changed the name to" DisplayS2cb" and the caption to "Display SECTION 2 text?"

    Step 2: Right-click the control and select View Code

    Step 3: Use the following code:

    Private Sub DisplayS2cb_Click()

        Dim ShowText As Range
        Dim HideText As Range
        
        Set ShowText = ActiveDocument.Bookmarks("SECTION2a").Range
        Set HideText = ActiveDocument.Bookmarks("SECTION2b").Range
        
        If DisplayS2cb.Value = True Then
            ShowText.Font.Hidden = False
            HideText.Font.Hidden = True
        Else
            ShowText.Font.Hidden = True
            HideText.Font.Hidden = False
        End If

    End Sub

    That's it! Feel free to use and modify to your hearts content.

    • Marked as answer by Jaynet Zhang Monday, May 21, 2012 1:37 AM
    Friday, May 18, 2012 2:45 PM

All replies

  • check this link this may help

    http://office.microsoft.com/en-us/word-help/create-forms-that-users-complete-or-print-in-word-HA101848148.aspx

    Wednesday, May 16, 2012 12:57 PM
  • Hi,

    I have an idea for you.

    Is it possible that make the form letter stored in a single page?

    Then if it is possible, then we can detele this page when the checkbox is selected.

    Make the checkbox unchecked as default when the document opens. 

    NOTE: If the checkbox is checked, the page deleted cannot show again. It means that the checkbox can only be changed once.

    The code is below (Suppose the page 2 is the page where the form letter stays):

    Private Sub CheckBox1_Change()

        If CheckBox1.Enabled = True Then

           Dim n As Integer, PageNum As Integer

       

            Dim delPageNum As String

               

            Dim lStart As Long, lEnd As Long

            delPageNum = "2"

            If delPageNum = "" Then Exit Sub

            PageNum = Selection.Information(wdNumberOfPagesInDocument)

            Selection.HomeKey wdStory 

            Do

               n = n + 1

                If n = Val(delPageNum) Then

                    lStart = Selection.Range.Start

                    If n = PageNum Then

                        lEnd = ActiveDocument.Content.End

                    Else

                        lEnd = Selection.GoToNext(wdGoToPage).End

                        Selection.GoToPrevious wdGoToPage

                    End If

                    ActiveDocument.Range(lStart, lEnd).Delete     

                    Exit Sub

                End If

       

                Selection.GoToNext wdGoToPage

              Loop

        End If

    End Sub


    Jaynet Zhang

    TechNet Community Support

    Thursday, May 17, 2012 6:26 AM
  • Hi Linda,

    Thanks for the link. Actually, this covers the basics of adding and configuring controls in Word doc, but I already know how to do that (I should have discussed what I've done so far). For a beginner, this link would be a great starting place.

    Thursday, May 17, 2012 2:33 PM
  • Deleting a page is not going to work but I know I'll need to write some code.

    I don't know how to share a doc on this forum, so I uploaded an example to Google Docs. You can access it from this link:

    https://docs.google.com/open?id=0ByDhIYEdFQPGamVBdWtFblRTOXc

    If you download it and view it in Word, you can see the comments I added to help explain what I'm hoping to accomplish.

    Thursday, May 17, 2012 3:26 PM
  • I solved my own question. For anyone who wants to know, here's the solution:

    First off, there are 3 different kinds of checkboxes in Word 2010. In the Developer section of the ribbon (you may have to add it), there's Check Box Content Control. Also in the same section of the ribbon, there a Legacy Tools icon that contains two more checkboxes. Under Legacy Forms, there's a Check Box Form Field, and under ActiveX Controls there's a Check Box (ActiveX Control). After messing around with all 3, I was only able to get the Check Box (ActiveX Control) to work.

    Step 1: Place the Check Box (ActiveX Control) into your document. Right-click on the control and select properties to change the name, caption, color, or anything else for the control. I changed the name to" DisplayS2cb" and the caption to "Display SECTION 2 text?"

    Step 2: Right-click the control and select View Code

    Step 3: Use the following code:

    Private Sub DisplayS2cb_Click()

        Dim ShowText As Range
        Dim HideText As Range
        
        Set ShowText = ActiveDocument.Bookmarks("SECTION2a").Range
        Set HideText = ActiveDocument.Bookmarks("SECTION2b").Range
        
        If DisplayS2cb.Value = True Then
            ShowText.Font.Hidden = False
            HideText.Font.Hidden = True
        Else
            ShowText.Font.Hidden = True
            HideText.Font.Hidden = False
        End If

    End Sub

    That's it! Feel free to use and modify to your hearts content.

    • Marked as answer by Jaynet Zhang Monday, May 21, 2012 1:37 AM
    Friday, May 18, 2012 2:45 PM