Word Form Fields & Macros

L

LPS

Working with Word 2000, I have a macro / form field problem which I hope I
explain clearly...

I have a macro that someone kindly gave me which is intended to add rows to
a table within a form. Upon exiting the last field in the last column of a
row, a new row in meant to be added which copies the form fields from the
current row into the new row, with all of their attributes.

Within the first row of form fields, there are three columns, each of which
contains a unique form field. The first is a generic text field, the second
is a drop-down list and the third is another generic text field. The macro
creates a new row with generic text fields; it does not copy / continue the
drop-down field in the second column. I need it to do this. The macro is
listed at the end of this post.

I am not very knowledgeable about macros so please bare with me; I am not
sure what the macro below is doing but can it be modified so that each of
the three form fields repeat in subsequent rows? Any and all help is hugely
appreciated. Cheers.

Sub addrow()
Dim rownum As Long, i As Long
Dim oRng As Word.Range
Dim oTbl As Table
Set oTbl = Selection.Tables(1)
ActiveDocument.Unprotect
oTbl.Rows.Add
rownum = oTbl.Rows.Count
For i = 1 To oTbl.Columns.Count
Set oRng = oTbl.Cell(rownum, i).Range
oRng.Collapse wdCollapseStart
ActiveDocument.FormFields.Add Range:=oRng, _
Type:=wdFieldFormTextInput
Next i
oTbl.Cell(oTbl.Rows.Count, oTbl.Columns.Count).Range.FormFields(1).ExitMacro
= "addrow"
oTbl.Cell(oTbl.Rows.Count, 1).Range.FormFields(1).Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
 
L

LPS

Hi again Doug. I tried the macro at the site you indicated and it is giving
me some kind of error, as follows,
with the first line "Sub NewRow()" highlighted in yellow and the last row
(listed below) just highlighted.
:

Sub Newrow()
'
' NewRow Macro
' Macro created 2006-Sep-26 by Linda Sgabellone

ActiveDocument.Unprotect
Selection.InsertRowsBelow 1
Selection.HomeKey Unit:=wdLine
Selection.FormFields.Add Range:=Selection.Range,


Can anyone explain what is going on?

Many thanks,
 
J

Jay Freedman

Because newsgroup posts are limited in line width, the macro you copied has
line breaks in the middle of statements that must be on one line in order to
work. The line you quoted is only the first of many. You have to delete the
line break that occurs after the comma at the end of that line, combining it
with the next line that starts with "Type".

Everywhere in the code that you see a line with red highlighting, you must
combine two lines. They'll usually be one line that's indented followed by a
second line that starts at the left margin.

In the future, if you want help with an error, it's best to quote *exactly*
the text of any error message -- "some kind of error" just doesn't cut it.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
L

LPS

Thank you for your suggestions Jay. I will try them. You are absolutely
correct about
providing exact error messages. I apologise if my post implied there was a
message;
there actually wasn't anything other than highlighted lines of code. Sorry
about that.

Cheers,
 

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