Referencing Mail Merge Field

M

Martin

Hi,

I've setup a macro that automatically pritns a mail merge
document when it's opened. The problem I am having is
that the mail merge is printed even if there are blank
fields. What I want to do is reference a mail merge field
in an If statement that will stop the document being
printed if that merge field is Null.

How can I do this?

Thanks

Martin
 
D

DA

Hi Martin

The following code is an example on how you can check if
there is any text in the field after the merge. It cycles
through each mailmerge field then sets a flag if it finds
an empty one. If the flag isn't set, the document prints.

'----------------
Sub Test4Empty()
Dim lngCounter As Long
Dim bVal As Boolean

With ActiveDocument
bVal = False
For lngCounter = 1 To .MailMerge.Fields.Count
.MailMerge.Fields(lngCounter).Select
If Selection.Text = "" Then bVal = True
Next
If bVal = False Then .PrintOut
End With
End Sub
'----------------

Hope that helps,
Dennis.
 

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