Re: Mailmerge Value in to a variable



The result depends on the state of

ActiveDocument.MailMerge.ViewMailMergeFieldCodes

You can also consider getting the current value of the mailmerge field using
e.g.

ActiveDocument.MailMerge.DataSource.DataFields("ClientCode")

Peter Jamieson

"Gaz uk" <Gazuk@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:49DBCE18-B186-48E9-A3A1-3492C2A4E1B4@xxxxxxxxxxxxxxxx
Hi

I'm having trouble getting the value of a mailmerge field in to a
variable.
I think I may be approaching this the wrong way but as a test I put the
following code into a template and instead of the actual value for CCode I
get <<ClientCode>>

Private Sub Document_New()
For Each mmField In ActiveDocument.Fields
If mmField.Code = " MERGEFIELD ClientCode " Then
CCode = mmField.Result
x = MsgBox("Client Code is " & CCode, vbOKOnly)
End If
Next mmField
End Sub

Is it that the value isn't coming in because the data hasn't merged yet?

I'm sure there is probably a straight forward answer but have dug around
and
found nothing that works.

Thanks in advance

Gaz


.