word and forms: updating a table by adding more rows

O

oj

Hello,

I have an ordering form that I created a while ago which I would
like to modify. In the form I have a table with columns for 'item
description', 'size', 'cost per unit', and 'quantity'. When the form
is protected users can fill in the descriptions and values. When
'quantity' and 'cost per unit' are filled in, a cell at the end of the
row automatically fills in with the subtotal. This table is fixed at
10 rows, and cell in another table automatically sums all the
subtotals together, adds in a predetermined amount of shipping and
handling charges and displays the result.
The question I have is: Is it possible to have the form open up
with two rows in the table (for filling in 'item description', 'size',
'cost per unit', and 'quantity'), and when the user fills in the
second row a third row appears (and if they fill in the third row, a
fourth row appears, etc.)? Could this happen and the total (in the
other table) be calculated as it is now?

Thanks.
 
D

Doug Robbins - Word MVP

' 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

End Sub

In addition, you will probably need to incorporate the code from the article
"How to assign a Name to a FormField that doesn't already have a Name, using
VBA" at:

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

so that you can name the new formfields and thus be able to reference them
in assigning a formula to the last formfield in each row so that it will
display the total for that row and also in a formula that calculated the
total of all of the rows.


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

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