Blank lines in conditional mail merge

M

Marie

Using Word 2000. Data from Access query.
I am getting blank lines from my code where there is not a
second company name and/or a second street address. I
have "suppress blank lines" checked in the mail merge
options. Also, I have studied Knowledge Base Article
264892 but can't figure out how to have my closing bracket
only at the end of the code--and not at the end of each
line. Also, I tried to cut and paste my code here, but it
wouldn't copy as code even though I removed the mail
merge, thus I may have a few minor typos in this
illustrative code, but you should be able to get the idea.


Here is my code: (The "brackets" look like parenthesis on
this screen but I did put them in with Cntl F9 in my
document.)

{If{fldContact1LastNamd}<>"""{fldContact1Title}
{fldContact1FirstNamd } {fldContact1LastName}"{If
{fldContact1Title }="" {If{fldContact1FirstName }
<>'''{fldContact1FirstNamd}"}}"{If{fodContact1LastName}
=""{If{fldContact1FirstName}="" "Purchasing"}}
{MERGEFIELD fldCompanyName}
{If{fldCompanyName@}<>"""{MERGEFIELD fldCompanyName2}"}
{MERGEFIELD fldCompanyMailing}
{If{fldCompanyMailing2}<>"""{fldCompanyMailing2}"}
{MERGEFIELD fldCity}, {MERGEFIELD fldState} {MERGEFIELD
fldZip}

I appreciate the help!
Marie
 
P

Peter Jamieson

I think what you need in the middle is something more like

{ MERGEFIELD fldCompanyName
}{ If { fldCompanyName@ }<> "" "
{ MERGEFIELD fldCompanyName2 }" "" }

As background...

1. The problem with the "suppress blank lines" feature is that "suppress
blank lines" is an inaccurate description. What it really means is that if
you have at least one MERGEFIELD

{ MERGEFIELD a }{ MERGEFIELD b }{ MERGEFIELD c }

and all the MERGEFIELDs on the line are blank, and there is no other text on
the line (not even spaces), the line will be suppressed. But if the
MERGEFIELDs are only inserted as the result of an IF field, Word behaves as
if there are no MERGEFIELDS on the line, and does not suppress the line even
if they are all blank.

So if for example you have a situation where you have mergefields A and B,
and you want "A B" (A space B) is non-blank, but no line at all if A is
blank, neither

{ IF "{ MERGEFIELD A }" = "" "" "{ MERGEFIELD A } { MERGEFIELD B }" }

nor

{ IF "{ MERGEFIELD A }" = "" "{ MERGEFIELD A }" "{ MERGEFIELD A } {
MERGEFIELD B }" }

will work (because Word will not suppress the line in the case where A is
blank). However, the following /will/ work:

{ MERGEFIELD A }{ IF "{ MERGEFIELD A }" = "" "" " { MERGEFIELD B }" }

2. Another way around this is to include paragraphs in the results of your
IF fields. So in the above example, you could instead use:

{ IF "{ MERGEFIELD A }" = "" "" "{ MERGEFIELD A } { MERGEFIELD B }
" }Immediately followed by whatever you want on the next line.

In this case, you just insert a new paragraph in the usual way (e.g.press
enter) immediately after the { MERGEFIELD B } field, so that the new
paragraph is part of the result inside the "".

3. While we're here, it's useful to realise that new paragraphs inside field
codes but outside results are not inserted by Word. So e.g.

{ IF "{ MERGEFIELD A }" = "" "" "{ MERGEFIELD A } { MERGEFIELD B }
" }Immediately followed by whatever you want on the next line.

and

{ IF "{ MERGEFIELD A }" = ""
""
"{ MERGEFIELD A } { MERGEFIELD B }
" }Immediately followed by whatever you want on the next line.

have exactly the same effect. This is useful because it allows you to lay
out your code in a more readable way, particularly when you are posting to
these newsgroups.

4. You may find the following small macro useful for converting your field
codes into a format that you can post to the newsgroups, either from the
Immediate window of the VB Editor or the document created by the macro.

Sub spelloutfieldcodes()
Dim r As Range
Dim i As Long
Dim s As String
Dim a As Long
Dim sfc As Boolean
Dim sht As Boolean
sfc = ActiveDocument.ActiveWindow.View.ShowFieldCodes
ActiveDocument.ActiveWindow.View.ShowFieldCodes = True
sht = ActiveDocument.ActiveWindow.View.ShowHiddenText
ActiveDocument.ActiveWindow.View.ShowHiddenText = True
Set r = Selection.Range
s = ""
For i = 1 To Len(r.Text)
a = AscW(Mid(r.Text, i, 1))
Select Case a
Case 1: s = s & "<inline graphic>"
Case 9: s = s & "<tab>"
Case 13: s = s & "¶" & ChrW(13)
Case 19: s = s & "{"
Case 21: s = s & "}"
Case Else
s = s & ChrW(a)
End Select
Next
Debug.Print s
Set r = Nothing
ActiveDocument.ActiveWindow.View.ShowFieldCodes = sfc
ActiveDocument.ActiveWindow.View.ShowHiddenText = sht

Dim d As Document
Set d = Documents.Add
d.Content.InsertAfter Text:=s
Set d = Nothing
End Sub
 
M

Marie

Peter,

Thanks so much. I got my merge out by the deadline
yesterday. But I don't understand the "but outside
results" in your sentence copied here. Do you mean outside
the code that makes the results?

While we're here, it's useful to realise that new
paragraphs inside field
codes but outside results are not inserted by Word.

Thanks,
Marie
 

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