R
Robert S.
I am working with Word 2002.
I have a table (2 columns wide), that has two empty
FormFields. When a user enters information in one of the
form fields, an exit macro is run, and a new row in the
table is created with new empty FormFields.
This all works fine. The problem is that I want Word to
give the newly created FormFields a bookmark name of my
choice.
In this 2 column table, two FormFields are created when
the exit macro is run, but only the FormField on the left
column has the bookmark applied to it. The bookmark for
the FormField in the right column remains blank.
HOWEVER, if I try to name the bookmark in the right column
first, and then the one in the left column second (see
code below), both than have their bookmarks names applied.
The only difference is the order in the code. For ex.
===============================================
Sub addrow()
Dim rownum As Integer
ActiveDocument.Unprotect
ActiveDocument.Tables(5).Rows.Add
rownum = ActiveDocument.Tables(5).Rows.Count
ActiveDocument.FormFields.Add Range:=ActiveDocument.Tables
(5).Cell(rownum, 2).Range, Type:=wdFieldFormTextInput
'BOOKMARK BEING APPLIED
ActiveDocument.Tables(5).Cell(rownum, 2).Range.FormFields
(1).Name = "ForeignEmployees" & rownum
ActiveDocument.FormFields.Add Range:=ActiveDocument.Tables
(5).Cell(rownum, 1).Range, Type:=wdFieldFormTextInput
' BOOKMARK BEING APPLIED
ActiveDocument.Tables(5).Cell(rownum, 1).Range.FormFields
(1).Name = "ForeignCountries" & rownum
ActiveDocument.Tables(5).Cell(rownum, 1).Range.FormFields
(1).ExitMacro = "addrow"
ActiveDocument.Tables(5).Cell(rownum, 1).Range.FormFields
(1).Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields,
NoReset:=True
End Sub
===========================================
The above code works, however if I switch order in which
the FormFields are named, only the left column FormField
is named, and the right one is blank.
===========================================
Sub addrow()
Dim rownum As Integer
ActiveDocument.Unprotect
ActiveDocument.Tables(5).Rows.Add
rownum = ActiveDocument.Tables(5).Rows.Count
ActiveDocument.FormFields.Add Range:=ActiveDocument.Tables
(5).Cell(rownum, 1).Range, Type:=wdFieldFormTextInput
' BOOKMARK BEING APPLIED TO LEFT COLUMN
ActiveDocument.Tables(5).Cell(rownum, 1).Range.FormFields
(1).Name = "ForeignCountries" & rownum
ActiveDocument.FormFields.Add Range:=ActiveDocument.Tables
(5).Cell(rownum, 2).Range, Type:=wdFieldFormTextInput
'BOOKMARK BEING APPLIED TO RIGHT COLUMN
ActiveDocument.Tables(5).Cell(rownum, 2).Range.FormFields
(1).Name = "ForeignEmployees" & rownum
ActiveDocument.Tables(5).Cell(rownum, 1).Range.FormFields
(1).ExitMacro = "addrow"
ActiveDocument.Tables(5).Cell(rownum, 1).Range.FormFields
(1).Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields,
NoReset:=True
End Sub
========================================
The above does not work correctly.
So, while the first subroutine was able to make the
program correctly, the quirkiness of this solution leaves
me confused. My problem now, is that I also have a table
with 3 columns that needs to work the same way, but no
matter which order I name the FormFields in the new row, I
can never have the name applied to the FormField in the
rightmost column.
I am guessing that the solution lies somewhere in the way
the bookmark name is applied. I hope someone can shed some
light on this situation. Thanks.
-Robert
I have a table (2 columns wide), that has two empty
FormFields. When a user enters information in one of the
form fields, an exit macro is run, and a new row in the
table is created with new empty FormFields.
This all works fine. The problem is that I want Word to
give the newly created FormFields a bookmark name of my
choice.
In this 2 column table, two FormFields are created when
the exit macro is run, but only the FormField on the left
column has the bookmark applied to it. The bookmark for
the FormField in the right column remains blank.
HOWEVER, if I try to name the bookmark in the right column
first, and then the one in the left column second (see
code below), both than have their bookmarks names applied.
The only difference is the order in the code. For ex.
===============================================
Sub addrow()
Dim rownum As Integer
ActiveDocument.Unprotect
ActiveDocument.Tables(5).Rows.Add
rownum = ActiveDocument.Tables(5).Rows.Count
ActiveDocument.FormFields.Add Range:=ActiveDocument.Tables
(5).Cell(rownum, 2).Range, Type:=wdFieldFormTextInput
'BOOKMARK BEING APPLIED
ActiveDocument.Tables(5).Cell(rownum, 2).Range.FormFields
(1).Name = "ForeignEmployees" & rownum
ActiveDocument.FormFields.Add Range:=ActiveDocument.Tables
(5).Cell(rownum, 1).Range, Type:=wdFieldFormTextInput
' BOOKMARK BEING APPLIED
ActiveDocument.Tables(5).Cell(rownum, 1).Range.FormFields
(1).Name = "ForeignCountries" & rownum
ActiveDocument.Tables(5).Cell(rownum, 1).Range.FormFields
(1).ExitMacro = "addrow"
ActiveDocument.Tables(5).Cell(rownum, 1).Range.FormFields
(1).Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields,
NoReset:=True
End Sub
===========================================
The above code works, however if I switch order in which
the FormFields are named, only the left column FormField
is named, and the right one is blank.
===========================================
Sub addrow()
Dim rownum As Integer
ActiveDocument.Unprotect
ActiveDocument.Tables(5).Rows.Add
rownum = ActiveDocument.Tables(5).Rows.Count
ActiveDocument.FormFields.Add Range:=ActiveDocument.Tables
(5).Cell(rownum, 1).Range, Type:=wdFieldFormTextInput
' BOOKMARK BEING APPLIED TO LEFT COLUMN
ActiveDocument.Tables(5).Cell(rownum, 1).Range.FormFields
(1).Name = "ForeignCountries" & rownum
ActiveDocument.FormFields.Add Range:=ActiveDocument.Tables
(5).Cell(rownum, 2).Range, Type:=wdFieldFormTextInput
'BOOKMARK BEING APPLIED TO RIGHT COLUMN
ActiveDocument.Tables(5).Cell(rownum, 2).Range.FormFields
(1).Name = "ForeignEmployees" & rownum
ActiveDocument.Tables(5).Cell(rownum, 1).Range.FormFields
(1).ExitMacro = "addrow"
ActiveDocument.Tables(5).Cell(rownum, 1).Range.FormFields
(1).Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields,
NoReset:=True
End Sub
========================================
The above does not work correctly.
So, while the first subroutine was able to make the
program correctly, the quirkiness of this solution leaves
me confused. My problem now, is that I also have a table
with 3 columns that needs to work the same way, but no
matter which order I name the FormFields in the new row, I
can never have the name applied to the FormField in the
rightmost column.
I am guessing that the solution lies somewhere in the way
the bookmark name is applied. I hope someone can shed some
light on this situation. Thanks.
-Robert