Consulting

Results 1 to 6 of 6

Thread: Auto Fill Legacy Form Fields using Checkbox

  1. #1

    Auto Fill Legacy Form Fields using Checkbox

    I would like to add a checkbox that will auto field form fields once it is checked. I have a word 2010 document where the user needs to fill in the physical address of a company, each field is a different form field. Example: Street: Text1, Province: Text2, Country: Text3, etc. Below I wish to have a Legal Address section with a statement that says "Same as physical address" with a check box. Once the box is checked I would like to have the values from the physical address form fields copied to the Legal Address fields. I need to keep the fields as legacy form fields instead of the newer content controls as I have a macro that transmits the values into excel using .FormFields function.

    Thanks for the help.

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    Run a macro something like this on exit from the checkbox:

    Sub FillLA()
      ActiveDocument.Unprotect
      If ActiveDocument.FormFields("Check1").CheckBox.Value = True Then
        ActiveDocument.FormFields("LegalAddress").Result = ActiveDocument.FormFields("Text1").Result & vbCr _
                                                           & ActiveDocument.FormFields("Text2").Result
      Else
        ActiveDocument.FormFields("LegalAddress").Result = vbNullString
      End If
      ActiveDocument.Protect wdAllowOnlyFormFields, True
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    Thank you! How would I alter this to include a drop down list entry? I add to change to change a form field to a Content Control Drop Down List and need to have the selection from DropDown1 copied to DropDown2. I have tried changing the .FormFields to .ContentCotnrol but it still doesn't seem to work with .Results. I have also tried .ContentControl("Drop1").DropDown.ListEntries which also gives me an error.

    Thanks

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    I don't exactly follow what you want to do. The displayed value of a content control can be returned like this e.g.,:

    Msgbox ActiveDocument.SelectContentControlByTitle("State").Item(1).Range.Text
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    Sorry for the delayed reply, I had to put my project on hold.
    I had to include a Content Control Drop Down List in the address to restrict the selection. Therefore, now when the user selects the checkbox I want the selection from DropDownList1 to appear as the selection in DropDownList2. Does this make more sense?

  6. #6
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    If you are going to use a content control checkbox then all the controls might as well be content controls. Following assumes the controls are named checkbox, dropdown1 and dropdown2. Code goes in the ThisDocument module:

    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
      Select Case ContentControl.Title
         Case "Checkbox"
           If ContentControl.Checked Then
             With ActiveDocument.SelectContentControlsByTitle("Dropdown2").Item(1)
               .Type = wdContentControlText
               .Range.Text = ActiveDocument.SelectContentControlsByTitle("Dropdown1").Item(1).Range.Text
               .Type = wdContentControlDropdownList
             End With
          End If
      End Select
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

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