Re: Reference Field Error!

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I wouldn't consider the necessary code to be simpler than the fields, but
very well...

Insert a bookmark starting at the left side of the first comma and ending at
the right side of the second comma. I named the bookmark "RefAttention", but
if you choose a different name you need only change the value assigned to
the constant BkmNm in the macro.

Sub DeleteErroredFields()
Const BkmNm = "RefAttention"
Dim bCodesVisible As Boolean

bCodesVisible = ActiveWindow.View.ShowFieldCodes
ActiveWindow.View.ShowFieldCodes = False

With ActiveDocument.Bookmarks
If .Exists(BkmNm) Then
.Item(BkmNm).Range.Fields.Update
If InStr(.Item(BkmNm).Range.Text, "Error!") Then
.Item(BkmNm).Range.Delete
End If
End If
End With

ActiveWindow.View.ShowFieldCodes = bCodesVisible
End Sub


singeredel wrote:
Thanks. I appreciate your input!

I have played with those complex field codes in the past and it is
just too confusing and I could never get it to work because I do need
to have the punctuation deleted also. I just preferred to have it in
the code to hopefully make it simpler.

singeredel wrote:
I have the following sentence and reference fields in a template:

Thank you, { REF AttentionTitle\* CharFormat } {REF
AttentionLineLast \* Charformat }, for allowing me to take part in
the care of your patient.

After running the program to create the document using the template,
sometimes the fields pertaining to these references are blank and
therefore it leaves the error message "Error! Reference Source not
found. Error! Reference Source not found" in the reference fields,
as follows:

"Thank you, { Error! Reference source not found. } { Error!
Reference source note found }, for allowing me to take part..."

I would like to know how to write code to just delete these messages
if these errors are found so that the text reads:

"Thank you for allowing me..."

Thanks!

You don't need macro code. What you do need is a somewhat complex
field code that displays a result only when it isn't the error
message. The first field becomes

{ IF { REF AttentionTitle } <> "Error! Reference source not found."
{ QUOTE ", { REF AttentionTitle \* CharFormat }" } }

and the second field becomes

{ IF { REF AttentionLineLast } <> "Error! Reference source not
found." { QUOTE "{ REF AttentionLineLast \*
Charformat }, " } }

Notice the placement of the commas inside the QUOTE field rather
than in the text outside the field -- if the fields don't display
anything, you don't want the commas either. You may have to play
with this a bit to get the placement of spaces to be correct.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.


.



Relevant Pages

  • Re: Formatting...
    ... Not sure I follow you completely but to kill everything from the first comma ... Now when I run the script the output is like this: ... How can I kill these extra commas? ...
    (microsoft.public.scripting.vbscript)
  • Re: Tony Coopers downhill slide
    ... >zeroed in on the undesirable interruption the first comma ... >to understand what the purpose of the comma was and probably ... >remark being punctuated as parenthetical. ... parenthetical phrase out of something that need not - even should not ...
    (alt.usage.english)
  • Re: Tony Coopers downhill slide
    ... >>>zeroed in on the undesirable interruption the first comma ... >>>to understand what the purpose of the comma was and probably ... This defense of the punctuation because it is the choice of the writer ... Especially since it's followed by a justified parenthetical phrase. ...
    (alt.usage.english)
  • Re: Elegant equivalent to this regex?
    ... (comma delimited) ... This would (worst case and highest specification) ... print join "\n", @hits; ...
    (comp.lang.perl.misc)
  • Re: Data from tables
    ... If Not .NoMatch Then ... Me.Bookmark = .Bookmark ... Run Time Error '3077' Syntax error (comma) in expression. ... What's in the control named Food? ...
    (microsoft.public.access.forms)