Calculating dynamic fields of another table

L

lbb4ever

Hello,

I have created a protected form document. This document has several tables.
One of them, specifically, was designed to generate new rows, complete with
formfields, when the user clicks a macrobutton. So this table can have one
row (sans the header row) or 20, if they so desire. I need to have another
field outside of this table which totals one of the said table's columns. I
am not sure how to reference this field to "autosum" this particular column
of this particular table.

Any help would be sooooooooooo appreciated :)

Thanks in advance!
 
L

lbb4ever

I believe I resolved my problem. I can call this from the onexit macro.

Sub runSum()
ActiveDocument.Unprotect
ActiveDocument.Tables(10).Range.Columns(4).Select
ActiveDocument.FormFields("bName").Result = Selection.Calculate
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
 
M

macropod

Hi lbb4ever,

The simple way to do this is to bookmark the table (Insert|Bookmark), then use an ordinary formula field coded as {=SUM(MyTable
C:C)}, where 'MyTable' is the bookmark name and 'C' is the column to be totalled. Provided the formfields have the 'calculate on
exit' property set, the total should update automatically.

Note: The field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy & paste
them from this message.

For more information on this and a wide range of other calculations in Word, check out my Word Field Maths Tutorial, at:
http://www.wopr.com/index.php?showtopic=365442
or
http://www.gmayor.com/downloads.htm#Third_party
 
L

lbb4ever

That works better than my solution - AND you gave me an idea how to fix
another issue I was having.

Interesting, though. I can select the table to create the bookmark. But when
I add the rows with the macrobutton, the bookmark does not expand to include
all the new rows. When I choose to "go to" the bookmark, it only selects the
initials two rows that were there when the bm was created. BUT, the solution
works anyway. Very interesting.

Thank you verrrry much :) I'll be sure to check out your tutorial....

macropod said:
Hi lbb4ever,

The simple way to do this is to bookmark the table (Insert|Bookmark), then use an ordinary formula field coded as {=SUM(MyTable
C:C)}, where 'MyTable' is the bookmark name and 'C' is the column to be totalled. Provided the formfields have the 'calculate on
exit' property set, the total should update automatically.

Note: The field brace pairs (ie '{ }') for the above example are created via Ctrl-F9 - you can't simply type them or copy & paste
them from this message.

For more information on this and a wide range of other calculations in Word, check out my Word Field Maths Tutorial, at:
http://www.wopr.com/index.php?showtopic=365442
or
http://www.gmayor.com/downloads.htm#Third_party

--
Cheers
macropod
[MVP - Microsoft Word]


lbb4ever said:
Hello,

I have created a protected form document. This document has several tables.
One of them, specifically, was designed to generate new rows, complete with
formfields, when the user clicks a macrobutton. So this table can have one
row (sans the header row) or 20, if they so desire. I need to have another
field outside of this table which totals one of the said table's columns. I
am not sure how to reference this field to "autosum" this particular column
of this particular table.

Any help would be sooooooooooo appreciated :)

Thanks in advance!
 

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