I am working on MS Word mail merge and trying to get
a field (which has multiple values) from the data
source file and then check if the substring of this field
contains a text, if true then insert some messages
into word document.
The macro code below does not work. I always have
problem with wdFirstRecord. The error message is
"requested object is not available". If I put dot in
front of it, error message is "Object required".
I am not familiar with VB. Please help!
Appreciate your help! Thank you in advance!
With DataSource
nub_conta =
ActiveDocument.MailMerge.DataSource.ActiveRecord
ActiveDocument.MailMerge.DataSource.ActiveRecord =
wdFirstRecord
For I = 1 To nub_conta
str_contact =
ActiveDocument.MailMerge.DataSource.DataFields("CONTACT_CODE"
If InStr(1, str_contact, "OL", vbTextCompare) >= 1
Then
With ActiveDocument.Paragraphs(1).Range
.InsertAfter "postcard from" & "College Outlook"
.InsertParagraphAfter
End With
End If
ActiveDocument.MailMerge.DataSource.ActiveRecord =
wdNextRecord
Next I
End With
a field (which has multiple values) from the data
source file and then check if the substring of this field
contains a text, if true then insert some messages
into word document.
The macro code below does not work. I always have
problem with wdFirstRecord. The error message is
"requested object is not available". If I put dot in
front of it, error message is "Object required".
I am not familiar with VB. Please help!
Appreciate your help! Thank you in advance!
With DataSource
nub_conta =
ActiveDocument.MailMerge.DataSource.ActiveRecord
ActiveDocument.MailMerge.DataSource.ActiveRecord =
wdFirstRecord
For I = 1 To nub_conta
str_contact =
ActiveDocument.MailMerge.DataSource.DataFields("CONTACT_CODE"
If InStr(1, str_contact, "OL", vbTextCompare) >= 1
Then
With ActiveDocument.Paragraphs(1).Range
.InsertAfter "postcard from" & "College Outlook"
.InsertParagraphAfter
End With
End If
ActiveDocument.MailMerge.DataSource.ActiveRecord =
wdNextRecord
Next I
End With