Running a macro to add a row in a table 
Author Message
 Running a macro to add a row in a table

I want to set up a document form in Word 97 that includes a table with two
rows - a title row and a data row.

Users will enter data in the respective row (possibly in fields) and when
they get to the end of that row another one is added to the bottom of the
table.  This last bit is done under normal circumstances, but I can't seem
to get to grips with doing this when the document is protected as a form,
unless I use fields across the row (15 in all) and have a macro run on
exiting the last field.

My difficulty is getting the values of the fields in the first row to stay
put!  If I unprotect, add a row and protect it again I lose all the data in
the rows above the added one.

To get around this, I've tried to convert the values of the bookmarks into
strings of text, delete the bookmark and replace it with the string, but
there doesn't seem to be a way of retrieving the value of the bookmark.

So my problems are these...

1.    Not losing the original data when I unprotect/protect the document
2.    Finding a much more sensible way to do the task

Any help would be appreciated.

Pete



Fri, 18 Jun 2004 21:26:30 GMT  
 Running a macro to add a row in a table
Hi Peter,

Quote:
> Users will enter data in the respective row (possibly in fields) and when
> they get to the end of that row another one is added to the bottom of the
> table.  This last bit is done under normal circumstances, but I can't seem
> to get to grips with doing this when the document is protected as a form,
> unless I use fields across the row (15 in all) and have a macro run on
> exiting the last field.

This is the way you have to go, so you're on the right track :-)

Quote:
> My difficulty is getting the values of the fields in the first row to stay
> put!  If I unprotect, add a row and protect it again I lose all the data in
> the rows above the added one.

Take a close look in the Word VBA Help at the .Protect method. There's an
argument in there - .NoReset - you need to set this to "True" to keep the
field content from resetting to its default.

A tip: if you're table rows need special formatting or content (sets of named
form fields, for example), it sometimes works to save the row as an AutoText
entry, and insert that. Save you a lot of coding :-)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.mvps.org/word
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)



Sat, 19 Jun 2004 16:40:43 GMT  
 Running a macro to add a row in a table
Thanks Cindy, I'll give it a go.

Have a Happy New Year :-)

Pete



Quote:
> Hi Peter,

> > Users will enter data in the respective row (possibly in fields) and
when
> > they get to the end of that row another one is added to the bottom of
the
> > table.  This last bit is done under normal circumstances, but I can't
seem
> > to get to grips with doing this when the document is protected as a
form,
> > unless I use fields across the row (15 in all) and have a macro run on
> > exiting the last field.

> This is the way you have to go, so you're on the right track :-)

> > My difficulty is getting the values of the fields in the first row to
stay
> > put!  If I unprotect, add a row and protect it again I lose all the data
in
> > the rows above the added one.

> Take a close look in the Word VBA Help at the .Protect method. There's an
> argument in there - .NoReset - you need to set this to "True" to keep the
> field content from resetting to its default.

> A tip: if you're table rows need special formatting or content (sets of
named
> form fields, for example), it sometimes works to save the row as an
AutoText
> entry, and insert that. Save you a lot of coding :-)

> Cindy Meister
> INTER-Solutions, Switzerland
> http://homepage.swissonline.ch/cindymeister
> http://www.mvps.org/word
> http://go.compuserve.com/MSOfficeForum

> This reply is posted in the Newsgroup; please post any follow question or
> reply in the newsgroup and not by e-mail :-)



Sat, 19 Jun 2004 16:50:08 GMT  
 Running a macro to add a row in a table

Peter -

Trick to not losing data is when you protect the form you set the NoReset
paramater to True.

Use something like this:-

ActiveDocument.Protect Type:= wdAllowOnlyFormFields, NoReset := True


Quote:
> I want to set up a document form in Word 97 that includes a table with two
> rows - a title row and a data row.

> Users will enter data in the respective row (possibly in fields) and when
> they get to the end of that row another one is added to the bottom of the
> table.  This last bit is done under normal circumstances, but I can't seem
> to get to grips with doing this when the document is protected as a form,
> unless I use fields across the row (15 in all) and have a macro run on
> exiting the last field.

> My difficulty is getting the values of the fields in the first row to stay
> put!  If I unprotect, add a row and protect it again I lose all the data
in
> the rows above the added one.

> To get around this, I've tried to convert the values of the bookmarks into
> strings of text, delete the bookmark and replace it with the string, but
> there doesn't seem to be a way of retrieving the value of the bookmark.

> So my problems are these...

> 1.    Not losing the original data when I unprotect/protect the document
> 2.    Finding a much more sensible way to do the task

> Any help would be appreciated.

> Pete



Sat, 19 Jun 2004 20:19:21 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. adding a table row, without setting same defaults as previous row

2. row heights of table rows added by vba

3. W97: Macro to create table (row x column) specified by user

4. How to Create 2 column table and continue adding rows

5. Format of Rows Added to a Table

6. Adding Rows to a Table

7. add text to table rows

8. Add row to the end of a table

9. Adding row to table is Slooooooow!

10. Adding new rows to related tables on a dataset

11. Help adding Table Rows dynamically Please!

12. Adding blank row in table

 

 
Powered by phpBB® Forum Software