none
Code in Word template is actually updating template rather than new Word doc RRS feed

  • Question

  • I've written some code to take a user form's data and update content controls.  It works fine when testing the template.  It doesn't work when testing in new doc created via the template.  The code executes when new doc is created, the user form is displayed and I'm able to fill the form and submit it, but the template is getting updated rather than the new doc.  I'm sure this is something really basic that I'm missing ... since I seldom create code.  I've attached the code below.

    Many thanks in advance,

    Chris

    Private Sub CommandButton_Update_Click()

        Dim cc As ContentControl
        Dim ccValue(12) As String
        Dim formValue(12) As String

        'collect form values
        formValue(1) = UserForm1.TextBox_ClientName.Value
        formValue(2) = UserForm1.TextBox_SowDate.Value
        formValue(3) = UserForm1.TextBox_ClientProject.Value
        formValue(4) = UserForm1.TextBox_City.Value
        formValue(5) = UserForm1.TextBox_State.Value
        formValue(6) = UserForm1.TextBox_ClientName.Value
        formValue(7) = UserForm1.TextBox_ProjectTitle.Value
        formValue(8) = UserForm1.TextBox_ClientPm.Value
        formValue(9) = UserForm1.TextBox_Bpfl_Pm.Value
        formValue(10) = UserForm1.TextBox_ProjectDate.Value
        formValue(11) = UserForm1.TextBox_ProjectTitle.Value
        formValue(12) = UserForm1.ComboBox_Services.Value
        
        For x = 1 To 12
            Set cc = ThisDocument.ContentControls(x)
            cc.Range.Text = formValue(x)
        Next x
        
        Unload Me

    End Sub

    Monday, August 17, 2015 5:24 PM

Answers

All replies