G
Guest
Hello,
I have a protected form that reads data from an external file into a field.
When it is in the form, I would like the data from the file to be formatted
as a numbered list.
The problem that I encounter is that the first item in the list will be
preceded by the appropriate list number, but none of the other lines have
any numbers. If I edit the field after the data has been read, new line
numbers will appear when I start a new line (i.e., press ENTER), but the
pre-existing lines as still without numbers.
Here is what I have. This code executes when entering a field.
Sub UpdateField()
Dim ReadLabel As Variant, ReadData As Variant, CurrentBookmark As Range
Set CurrentBookmark = ActiveDocument.Bookmarks(Selection.Bookmarks_
(Selection.Bookmarks.Count)).Range
' Open the file and read until the data label matches the bookmark name then
read the next piece of data and assign it to the bookmark
Open "C:\My documents\Summary.txt" For Input As #1
Do Until ReadLabel = Selection.Bookmarks(Selection.Bookmarks.Count).Name
Input #1, ReadLabel
Loop
Input #1, ReadData
Close #1
ActiveDocument.FormFields(Selection.Bookmarks_
(Selection.Bookmarks.Count).Name).Result = ReadData
End If
' Format the bookmark as a numbered list
CurrentBookmark.Fields(1).Result.Select
CurrentBookmark.ListFormat.ApplyListTemplate
ListTemplate:=ListGalleries_
(wdNumberGallery).ListTemplates(1), _
ContinuePreviousList:=False, ApplyTo:=wdListApplyToSelection
End Sub
The "Summary.txt" file may look like this:
"Apple","red<CR>delicious<CR>juicy","Lemon","yellow<CR>sour"
I would like the output to look like this:
(In the "Apple" bookmark)
1. red
2. delicious
3. juicy
(In the "Lemon" bookmark)
1. yellow
2. sour
What am I doing wrong?
-Brian
I have a protected form that reads data from an external file into a field.
When it is in the form, I would like the data from the file to be formatted
as a numbered list.
The problem that I encounter is that the first item in the list will be
preceded by the appropriate list number, but none of the other lines have
any numbers. If I edit the field after the data has been read, new line
numbers will appear when I start a new line (i.e., press ENTER), but the
pre-existing lines as still without numbers.
Here is what I have. This code executes when entering a field.
Sub UpdateField()
Dim ReadLabel As Variant, ReadData As Variant, CurrentBookmark As Range
Set CurrentBookmark = ActiveDocument.Bookmarks(Selection.Bookmarks_
(Selection.Bookmarks.Count)).Range
' Open the file and read until the data label matches the bookmark name then
read the next piece of data and assign it to the bookmark
Open "C:\My documents\Summary.txt" For Input As #1
Do Until ReadLabel = Selection.Bookmarks(Selection.Bookmarks.Count).Name
Input #1, ReadLabel
Loop
Input #1, ReadData
Close #1
ActiveDocument.FormFields(Selection.Bookmarks_
(Selection.Bookmarks.Count).Name).Result = ReadData
End If
' Format the bookmark as a numbered list
CurrentBookmark.Fields(1).Result.Select
CurrentBookmark.ListFormat.ApplyListTemplate
ListTemplate:=ListGalleries_
(wdNumberGallery).ListTemplates(1), _
ContinuePreviousList:=False, ApplyTo:=wdListApplyToSelection
End Sub
The "Summary.txt" file may look like this:
"Apple","red<CR>delicious<CR>juicy","Lemon","yellow<CR>sour"
I would like the output to look like this:
(In the "Apple" bookmark)
1. red
2. delicious
3. juicy
(In the "Lemon" bookmark)
1. yellow
2. sour
What am I doing wrong?
-Brian