Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
All -
Trying to get this working:
set fld=ActiveDocument.GetField(1)
msgbox(fld.Name)
What I think this is supposed to do is access the array of fields returned by the load script by index number rather than by name. What actually happens is:
Executing the code this way proces the desired result:
sub create_chart2()
set fld = ActiveDocument.GetField("Product")
txtName = fld.Name
msgbox(txtName)
end sub
Am I off target by assuming that the Example in the API Guide for GetFiel is using an array index?
Digging around the API Guide, I found something that may work, but it's a little messier.
Sub Test
set flds = ActiveDocument.GetFieldDescriptions
for i = 0 to flds.Count - 1
set fld = flds.item(i)
if not fld.IsSystem then
txtName = fld.Name
msgbox(txtName)
end if
next
End Sub
That allows you to loop through every field. Unfortunately, that loop gets you System Fields, so I added the IsSystem check to check for those.
As far as I understand, the example may be wrong, as you can access objects in two ways. One is referencing the object by name (as you did in your code example), and the other would be:
sub create_chart2()
set fld = ActiveDocument.Fields(1)//change number/reference to get the number in the object array
txtName = fld.Name
msgbox(txtName)
end sub
Regards.
Thanks for the response:
Unfortunately that gives me the same error:
Object required:'fld'
EDIT: Sorry, I misunderstood your post. You want to use the field array. Please ignore. ![]()
Try this:
sub create_chart2()
set fld = ActiveDocument.Fields("Product")
txtName = fld.Name
msgbox(txtName)
end sub
It seems there are a few ways to reference fields. There was a brief discussion in one of these threads a while back, but I don't think anyone came up with a difference.
So if it is impossible to reference a loadscript field by array index, is there any way to dynamically create a chart that displays all fields loaded in the script?
The manual adding would be a deal breaker as it would more or less require a huge manual effort to add each field through the wizard, every time we wanted to consider a different table...
Digging around the API Guide, I found something that may work, but it's a little messier.
Sub Test
set flds = ActiveDocument.GetFieldDescriptions
for i = 0 to flds.Count - 1
set fld = flds.item(i)
if not fld.IsSystem then
txtName = fld.Name
msgbox(txtName)
end if
next
End Sub
That allows you to loop through every field. Unfortunately, that loop gets you System Fields, so I added the IsSystem check to check for those.
Thanks all, NMiller got it!
wytworm wrote:there any way to dynamically create a chart that displays all fields loaded in the script?
The system field '$Field" contains a row for every field present in the document. $Field can be used in a chart. Is that what you are looking for?
-Rob