What do I use to display userform data in a Word 2010 template: fields or controls?

Posted on 2011-04-21
Last Modified: 2012-05-11

I've created a userform in Word 2010 template where users can insert data such as their name, phone number and the add our customer's address and name.

Should I use fields or the new Word controls to display them in the document?

I'm new to Word programming. Thanks for your help/feedback.
Question by:mscola
    LVL 76

    Accepted Solution

    The biggest problem is knowing whereabouts on the document to put the data.

    There are various techniques: Legacy form fields,  bookmarks, content controls, tables or replaceable pilot text (e.g. <New Text here>.

    Unless you have any problems, then use the new content controls. The main problem is in finding the right one. There is (in 2007, anyway), no direct way of getting a Content Control be name. You will have to step through the ContentControls collection an look for one with the Tag or Title (neither automatically unique) that you have given it.

    For the others:

    Form fields are easiest to program for, but to work properly, the document must be protected.

    Bookmarks can easily be deleted, and require come slightly fiddly programming it you want to replace the existing text.

    Tables are quite good, especially if you want to control the precise placing at the same time.

    LVL 76

    Assisted Solution

    Here are some one-line examples:

    Form Fields:

    ActiveDocument.FormFields("MyField").Result = TextBox1.Text


    ActiveDocument.Bookmarks("MyBookmark").Range.Text = TextBox1.Text


    ActiveDocument.Tables(1).Cell(1,1).Range.Text = TextBox1.Text

    Content Controls

    Activedocument.ContentControls(1).Range.Text = TextBox1.Text
    LVL 76

    Assisted Solution

    Here is a pilot text example:

        With ActiveDocument.Range.Find
            .Text = "<ReplaceMe>"
            .Replacement.Text = TextBox1.Text
            .Execute Replace:=wdReplaceAll
        End With

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
    Outlook Free & Paid Tools
    Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now