Inserting repetitive formfields based on field entry

A

Alan D.

Here's what I'm hoping to do: I have a field that requests how many
locations are needed. Once that's filled in (x), the macro inserts x sets of
fields, each set being titled "Location (1 - x)". The fields are all used
for a per-location calculation as well and so need to be uniquely named as
well. Thanks for any assistance!

Alan D.
 
D

Doug Robbins - Word MVP

Hi Alan,

This code does not do exactly what you want, but, in conjuction with the
following link should show you how you can go about it:

' Throw Away Macro created 02/02/03 by Doug Robbins
' to add a new row to a table containing formfields in every column
' automatically on exit from the last cell in the present last row of the
table
Dim rownum As Integer, i As Integer
ActiveDocument.Unprotect
ActiveDocument.Tables(1).Rows.Add
rownum = ActiveDocument.Tables(1).Rows.Count
For i = 1 To ActiveDocument.Tables(1).Columns.Count
ActiveDocument.FormFields.Add
Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range,
Type:=wdFieldFormTextInput
Next i
ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
ActiveDocument.Tables(1).Columns.Count).Range.FormFields(1).ExitMacro =
"addrow"
ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
1).Range.FormFields(1).Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

See the article “How to assign a Name to a FormField that doesn't already
have a Name, using VBA” at:

http://word.mvps.org/FAQs/MacrosVBA/AssignNameToFmFld.htm


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top