Table in Protected form that grows?

A

allie357

I added form fields to a table in a protected form which is fine when
I just fill in the rows that are on the original table. However, when
I try to tab and add more rows to the table these rows do not have
form fields in them and hence are not able to be filled in when the
form is protected. So, the table cannot currently grow. Is there a
way to fix this with or without vba
Thanks!
 
J

Jay Freedman

I added form fields to a table in a protected form which is fine when
I just fill in the rows that are on the original table. However, when
I try to tab and add more rows to the table these rows do not have
form fields in them and hence are not able to be filled in when the
form is protected. So, the table cannot currently grow. Is there a
way to fix this with or without vba
Thanks!

Yes, there is a way, only through VBA.

You need a macro that first unprotects the document, then inserts a new table
row and inserts form fields into the appropriate cells (and possibly text in
other cells), and finally reprotects the document.

The first task is done with code like this:

With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect
End If
End With

If the protection has been applied with a password, the .Unprotect statement
needs to include the optional Password argument, like this:

.Unprotect Password:="gnS4fgm"

The last task, at the end of the macro, is done by the code

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

The NoReset argument prevents Word from clearing the contents of existing
fields.

Between those two, you need code to add one or more rows to the table, insert
text and form fields in the proper cells, and assign names to the fields (see
http://www.word.mvps.org/FAQs/MacrosVBA/AssignNameToFmFld.htm for help with
that).
 
G

Gordon Bentley-Mix

Allie,

Jay is spot on with the code for adding a row to a table in a protected
form: unprotect the form; add the row; re-protect the form.

However, what's missing is a method for invoking this code. I suspect you'll
need something like a custom toolbar (or at least a custom button added to an
existing toolbar) or possibly a keyboard shortcut.

In addition, as Jay pointed out, you'll need code and a "source" of the
content for the additional row - especially if you want it to have text or
additional form fields in the newly added row. An AutoText entry would
probaly work best for this, although it could all be done in code.

Finally, you might want to consider some sort of method for deleting a row
if the user decides they don't need it after all. You'll run into the same
problem trying to delete content from a protected form as you do with adding
content.

For a skilled developer all of this would be quite simple, but if you don't
have any experience with VBA, you may run into problems. I'd suggest starting
by doing the process manually whilst running the macro recorder and then
going from there. If you run into problems, post back and someone will
probably be able to help.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
D

Doug Robbins - Word MVP

Set the following macro to run on exit from the formfield in the last column
of the table:

' 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

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