Adding row to table with form fields

D

dave.cuthill

I have a macro that is prompted when exiting the last cell in the last
row of a forms table to add another row. This works fine but I want to
also duplicate the form field properties for the previous row. Is
there an easier way to do this than moving through and adding the
formfields and appropriate properties to all the cells in the newly
added row?

Hope that makes some sense.
 
D

Doug Robbins - Word MVP

Have the following macro run on exit from the last formfield in the last row

Sub addrow()
'
' 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

End Sub


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

Graham Mayor

There's an example on my web site at
http://www.gmayor.com/word_vba_examples.htm under the sub heading "Add a row
to a table in a protected form" which demonstrates how to add a row to a
table and complete the properties for the cells in that new row including
unique bookmark names.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

dave.cuthill

Thank you both - I have been using Doug's method to add the row but
some of the fields are dropdowns so what I ended up doing was to step
through each cell and add the appropriate field to the newly created
row.

I have been unable looked at Graham's example as the site is blocked
by my IT people for some odd reason. I will have to look from home.

David
 
G

Graham Mayor

I have been unable looked at Graham's example as the site is blocked
by my IT people for some odd reason. I will have to look from home.

David

All that work and some net nazi prevents users from accessing it :(

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
S

Suzanne S. Barnhill

I don't know why they'd block yours, but all of my sites that are at
home.earthlink.net (free sites associated with email aliases) are blocked by
many corporate firewalls. Unfortunately, one of these is the site I maintain
for my Rotary club, so many of my fellow Rotarians can't access our site
from work. <sigh>

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 

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