Difficulty assessing state of field

B

Brett Thompson

Hi all. Hope someone can help me with this.
I use the following code to pull a bookmark that marks a table from an open
document to the active document.

WhichDoc$ = ActiveDocument.Variables("WhichPath").Value
ActiveDocument.Fields.Add Range:=Selection.Range, Type:=wdFieldIncludeText,
Text:=Chr(34) + WhichDoc$ + Chr(34) + "MedicationList" + Chr(34)
With Selection
.Fields.Update
.GoTo What:=wdGoToField, Which:=wdGoToPrevious, Count:=1
If .Information(wdWithInTable) = True Then

The last line is to assess if the table was present, or whether the bookmark
was empty or marked something unrelated (error in the structure of the
document which is being referenced).

The problem is if the after insertion the field is toggled to show the field
code rather than the field result then the result is never within a table.
I'm not sure why this happens - usually it will appear as the field result,
but sometimes the field code appears.
Now, if I could assess if it was the field code that was visible before
assessing the wdWithInTable) this would not be a problem, but if I use
.Fields(1).ShowCodes
to assess the field state an error is trigger saying that "The requested
member of the collection does not exist."
For some reason, even though a field is present, ActiveDocument.Fields.Count
is 0.

Is there a way to assess the state of a selected field to know its state, or
can someone suggest another way around this.
I've tried using the document object to pull across the content of the
bookmark, but it comes across as text, not the original table.

Many thanks in advance.
Brett
 
D

Doug Robbins - Word MVP

Hi Brett,

Use the following to ensure that the display of field codes is turned off

If ActiveWindow.View.ShowFieldCodes = True Then
ActiveWindow.View.ShowFieldCodes = Not
ActiveWindow.View.ShowFieldCodes
End If

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
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