none
Create a single document with multiple instances of a form RRS feed

  • Question

  • I have a Word 2007 doc that uses legacy controls. (I can update to content controls if I need to.) Basically, this document is a one-page form.

    The form is a final inspection checklist for, let's say, widgets coming off the assembly line.

    Each day in the factory, I will be producing a different number of widgets. Each will have a unique serial number. The serial numbers are known at the beginning of the day.

    I want to create a single Word doc that has the one-page form repeated as many times as necessary to have one page for each widget. I would also like to prepopulate one of the form fields with the widget's serial number. I want to give this Word doc to the inspector at the beginning of the work day so that as widgets roll off the assembly line, he can tab through the fields of the form and fill out the form for each widget.

    How can I accomplish this? I can live with alternate solutions I suppose, but I really need it to be a single document rather than a separate document for each widget.

    Thursday, January 20, 2011 3:49 AM

Answers

  • Here's a simpler way.

    Format the first paragraph in your document so that it has a Page Break Before it (via the Format Paragraph dialog) and assign the bookmark name WidgetNumber to the formfield that is to contain the Widget Number.  For that formfield, uncheck the "Fill-in enabled" box.   Do not protect the document, as that will prevent access to the macros dialog.  Create a macro containing the following code

    Dim FirstWidget As Long
    Dim numWidgets As Long
    Dim i As Long
    Dim rng As Range
    Dim source As Document
    Dim target As Document
    FirstWidget = InputBox("Enter the number of the first Widget", "Starting Number")
    numWidgets = InputBox("Enter the number of Widget to be produced", "Number of Widgets")
    Set source = ActiveDocument
    Set target = Documents.Add
    For i = 0 To numWidgets
       source.FormFields("WidgetNumber").result = FirstWidget + i
       source.Range.Copy
       Set rng = target.Range
       rng.Collapse wdCollapseEnd
       rng.Paste
    Next i
    target.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

    Run that macro when the document containing the formfields is the active document.  It will ask you for the number of the first Widget and the number of Widgets to be produced and then it will create a document with a page for each Widget with the formfield for the Widget number already populated.


    Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "NogginBoink" wrote in message news:bb6125c3-e6a2-48b7-9be8-0c4720f09095@communitybridge.codeplex.com...

    I have a Word 2007 doc that uses legacy controls. (I can update to content controls if I need to.) Basically, this document is a one-page form.

    The form is a final inspection checklist for, let's say, widgets coming off the assembly line.

    Each day in the factory, I will be producing a different number of widgets. Each will have a unique serial number. The serial numbers are known at the beginning of the day.

    I want to create a single Word doc that has the one-page form repeated as many times as necessary to have one page for each widget. I would also like to prepopulate one of the form fields with the widget's serial number. I want to give this Word doc to the inspector at the beginning of the work day so that as widgets roll off the assembly line, he can tab through the fields of the form and fill out the form for each widget.

    How can I accomplish this? I can live with alternate solutions I suppose, but I really need it to be a single document rather than a separate document for each widget.


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    • Marked as answer by Bessie Zhao Thursday, January 27, 2011 10:18 AM
    Thursday, January 20, 2011 10:05 AM

All replies

  • If you have the Widget numbers for each day in an Excel Workbook, you could use the information on the following page of fellow MVP Graham Mayors website to produce the documents via Mail Merge

    See the article “Combining FormFields and Mail Merge” on the following page of fellow MVP Graham Mayor’s website:

    http://www.gmayor.com/Form_Fields_and_Mail_Merge.htm
     -- Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "NogginBoink" wrote in message news:bb6125c3-e6a2-48b7-9be8-0c4720f09095@communitybridge.codeplex.com...

    I have a Word 2007 doc that uses legacy controls. (I can update to content controls if I need to.) Basically, this document is a one-page form.

    The form is a final inspection checklist for, let's say, widgets coming off the assembly line.

    Each day in the factory, I will be producing a different number of widgets. Each will have a unique serial number. The serial numbers are known at the beginning of the day.

    I want to create a single Word doc that has the one-page form repeated as many times as necessary to have one page for each widget. I would also like to prepopulate one of the form fields with the widget's serial number. I want to give this Word doc to the inspector at the beginning of the work day so that as widgets roll off the assembly line, he can tab through the fields of the form and fill out the form for each widget.

    How can I accomplish this? I can live with alternate solutions I suppose, but I really need it to be a single document rather than a separate document for each widget.


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Thursday, January 20, 2011 5:36 AM
  • Hi NogginBoink

    Following up on Doug's reply, this widget numbers need not be in an Excel workbook, it could be any datasource, even an SQL SP.

    If you really want to stick with the form field approach (and I can see why you might want to, given that the inspector will probably want to "fill in the blanks"):

    When I've needed something like this I've saved the form "page" as an AutoText entry in the document's template. In Office 2007 "Builing Blocks" have replaced AutoText, but the principle remains the same.

    The tricky part is going to be filling in the field for the widget number, as your code probably wants to address the form field name. A form field name is also a bookmark, and these names must be unique in the document. What I usually do is give the form fields I'm going to store as Building Blocks a "base name". The form fields in the template (from which the document is created) are basename & 1 (the numeral 1). Each time my code inserts the Building Block section it goes through and supplements the basename by an incremented number. Then the data can be written to the form field(s) as required...

    ...And I assume at some point you'll also have software reading this data out of the forms, so it will also be important for that to be able to distinguish the form fields.

    Note that this could also be accomplished with content controls. If you're an accomplished .NET programmer that could even be more efficient since you could do it using OpenXML. But I'll leave things as they are for the moment :-)


    Cindy Meister, VSTO/Word MVP
    Thursday, January 20, 2011 9:03 AM
    Moderator
  • Here's a simpler way.

    Format the first paragraph in your document so that it has a Page Break Before it (via the Format Paragraph dialog) and assign the bookmark name WidgetNumber to the formfield that is to contain the Widget Number.  For that formfield, uncheck the "Fill-in enabled" box.   Do not protect the document, as that will prevent access to the macros dialog.  Create a macro containing the following code

    Dim FirstWidget As Long
    Dim numWidgets As Long
    Dim i As Long
    Dim rng As Range
    Dim source As Document
    Dim target As Document
    FirstWidget = InputBox("Enter the number of the first Widget", "Starting Number")
    numWidgets = InputBox("Enter the number of Widget to be produced", "Number of Widgets")
    Set source = ActiveDocument
    Set target = Documents.Add
    For i = 0 To numWidgets
       source.FormFields("WidgetNumber").result = FirstWidget + i
       source.Range.Copy
       Set rng = target.Range
       rng.Collapse wdCollapseEnd
       rng.Paste
    Next i
    target.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

    Run that macro when the document containing the formfields is the active document.  It will ask you for the number of the first Widget and the number of Widgets to be produced and then it will create a document with a page for each Widget with the formfield for the Widget number already populated.


    Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "NogginBoink" wrote in message news:bb6125c3-e6a2-48b7-9be8-0c4720f09095@communitybridge.codeplex.com...

    I have a Word 2007 doc that uses legacy controls. (I can update to content controls if I need to.) Basically, this document is a one-page form.

    The form is a final inspection checklist for, let's say, widgets coming off the assembly line.

    Each day in the factory, I will be producing a different number of widgets. Each will have a unique serial number. The serial numbers are known at the beginning of the day.

    I want to create a single Word doc that has the one-page form repeated as many times as necessary to have one page for each widget. I would also like to prepopulate one of the form fields with the widget's serial number. I want to give this Word doc to the inspector at the beginning of the work day so that as widgets roll off the assembly line, he can tab through the fields of the form and fill out the form for each widget.

    How can I accomplish this? I can live with alternate solutions I suppose, but I really need it to be a single document rather than a separate document for each widget.


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    • Marked as answer by Bessie Zhao Thursday, January 27, 2011 10:18 AM
    Thursday, January 20, 2011 10:05 AM