M
Matthew Chan
I have find the following code to overwrite the mailmerge field with the
recordset value. but find error occur while there is null field of recordset
value.
loWordApp.Documents.Add (asMergeDoc) 'Add an instance For Each record
Set loDoc = loWordApp.ActiveDocument 'Utilize newest instance
loDoc.Activate
Do Until aors.EOF
ReDim lsaFldNames(loDoc.MailMerge.Fields.Count)
Debug.Print loDoc.Fields.Item(1).Code
For Nc = 1 To loDoc.MailMerge.Fields.Count
lsFieldName =
Trim(Right(loDoc.MailMerge.Fields(Nc).Code,
Len(loDoc.MailMerge.Fields(Nc).Code) - 11))
lsaFldNames(Nc) = lsFieldName
Next Nc
For Nc = 1 To loDoc.MailMerge.Fields.Count
loDoc.MailMerge.Fields(1).Select
lbmatched = False
For llmatch = 0 To UBound(larrTTXField)
If larrTTXField(llmatch) = lsaFldNames(Nc) Then
lbmatched = True
Exit For
End If
Next
If lbmatched = True Then
If Trim(aors(lsaFldNames(Nc))) = "" Then
Else
loGlobVar.Selection.TypeText
Trim(aors(lsaFldNames(Nc)))
End If
End If
Next Nc
loDoc.MailMerge.Destination = wdSendToNewDocument
loDoc.SaveAs asOutputFullPathFilename
aors.MoveNext
Loop
aors.Close
loWordApp.Quit
recordset value. but find error occur while there is null field of recordset
value.
loWordApp.Documents.Add (asMergeDoc) 'Add an instance For Each record
Set loDoc = loWordApp.ActiveDocument 'Utilize newest instance
loDoc.Activate
Do Until aors.EOF
ReDim lsaFldNames(loDoc.MailMerge.Fields.Count)
Debug.Print loDoc.Fields.Item(1).Code
For Nc = 1 To loDoc.MailMerge.Fields.Count
lsFieldName =
Trim(Right(loDoc.MailMerge.Fields(Nc).Code,
Len(loDoc.MailMerge.Fields(Nc).Code) - 11))
lsaFldNames(Nc) = lsFieldName
Next Nc
For Nc = 1 To loDoc.MailMerge.Fields.Count
loDoc.MailMerge.Fields(1).Select
lbmatched = False
For llmatch = 0 To UBound(larrTTXField)
If larrTTXField(llmatch) = lsaFldNames(Nc) Then
lbmatched = True
Exit For
End If
Next
If lbmatched = True Then
If Trim(aors(lsaFldNames(Nc))) = "" Then
Else
loGlobVar.Selection.TypeText
Trim(aors(lsaFldNames(Nc)))
End If
End If
Next Nc
loDoc.MailMerge.Destination = wdSendToNewDocument
loDoc.SaveAs asOutputFullPathFilename
aors.MoveNext
Loop
aors.Close
loWordApp.Quit