我正在尝试实现一个例程,该例程用保存在SQL Server上的数据填充Word模板。我遇到了错误“ 5631” [Word无法将主文档与数据源合并,因为数据记录为空或没有数据记录与您的查询选项匹配”] 指向“。执行暂停: = false”
我真的不知道出现此问题的原因。谢谢您的帮助。
这是代码段:
Set wrdApp = CreateObject("Word.Application")
With wrdApp
Set wrdDoc = .Documents.Add(sTemplate, False)
With wrdDoc.MailMerge
.MainDocumentType = wdFormLetters
.OpenDataSource Name:="d:\connect.odc" _
, ConfirmConversions:=False _
, ReadOnly:=False _
, LinkToSource:=False _
, AddToRecentFiles:=False _
, Revert:=False _
, Format:=wdOpenFormatAuto _
, Connection:=EPLconnectWord(bAcc) _
, SQLStatement:="SELECT * FROM [" & sTable & "] WHERE [UserID] = " & lUserID _
, SQLStatement1:="" _
, SubType:=wdMergeSubTypeOther
If .State = wdMainAndSourceAndHeader Or .State = wdMainAndDataSource Then
.ViewMailMergeFieldCodes = False
End If
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
wrdDoc.ActiveWindow.View.ShowFieldCodes = False
wrdDoc.Close wdDoNotSaveChanges
End With ' wrdDoc.MailMerge