View Single Post
  #2   Report Post  
Posted to microsoft.public.word.tables
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Document with multiple tables, form fields, bookmarks and calculat

The following macro run on exit from the formfield in the last cell of the
last row of a table will add another row to the table and insert formfields
into each of the cells in that row:

' 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
Dim Response
Response = MsgBox("Do you want to add another row ?", vbYesNo)
If Response = vbYes Then ' User chose Yes.
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.Table s(1).Rows.Count,
ActiveDocument.Tables(1).Columns.Count).Range.Form Fields(1).ExitMacro =
"addrow"
ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
1).Range.FormFields(1).Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End Sub

It would need modifying if you need calculation type formfields in some of
the cells.

While it is possible to create such a form using form fields, I would really
recommend that it be done with a userform.

See the article "How to create a Userform" at:

http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm



--
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

"Carl Bentz" Carl wrote in message
...
I am trying to create a general "estimate" document for service advisors to
complete for their customers. Two of five tables (Tables 1 and 2) would
simply contain text form fields to simplify data entry. Two more of the
tables (Tables 3 and 4) would/could include multiple lines that would
include
calculations (sum and percentage of) and both might need to have
additional
rows added, if more options for service/repair work was required. One
final
table would be an overview that calculated a subtotal, miscellaneous (a %
of
calculation), a sales tax calculation and a grand total. The subtotal and
Miscellaneous items would be taken from Tables 3 and 4. - The users are
currently working with Word 2000. My development work is in Word 2003 at
present. -
Question 1. Is it possible to add additional rows to a table and have the
form field definitions be retained in the added rows?
Question 2. Can these calculations be done without resorting to a "button"
and VBA to initiation the math? [I did find an Update option that did the
calculations with individual tables, but could not get the information
from
one table to another to work.]
Question 3. Can you tell me more about using Bookmarks and cell names in
order to refer to one or more cells in other tables in order to make
calculations - for example create a sum from a "totals" cell in Table 3
and a
"totals" cell in Table 4.
Thank you in advance for any ideas and assistance.