Word无法将主文档与数据源合并,因为数据记录为空或没有与查询选项匹配的数据记录。 [英] Word could not merge the main document with the data source because the data records were empty or no data records matched your query options.

查看:2551
本文介绍了Word无法将主文档与数据源合并,因为数据记录为空或没有与查询选项匹配的数据记录。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的就是在我的申请表中邮寄来自单个客户记录的信件。这就是全部。

All I wish to do is mailmerge a letter from a single customer record in my application. That is all.

我想做的是让一个微软产品与另一个产品对话。 VB.NET和Word 2007.现在我用Word 2003做得很好,但似乎是自动邮件发送的新功能,称为'命令失败'。

What I want to do is make one microsoft product talk to another one. VB.NET and Word 2007. Now what I had worked fine with Word 2003, but there seems to be a new feature to automated mailmerging called 'Command Failed'.

我有一个号码.odc文件,有些已直接链接到表,一个只是进入数据库,然后使用在构建.odc文件时已创建的数据库连接对话框对屏幕进行加密。不知道为什么,也不起作用

I have a number of .odc files, some have been linked directly to tables, one just goes to the database and then peppers the screen with database connection dialogs that have already been created when the .odc file was built. Don't know why, doesn't work either.

这是我的代码。

      ;      Dim connectionstring As String = String.Format(" Provider = SQLNCLI10; Server = {0}; Data Source = Alarm64; Uid =?; Pwd =?;",GetServernameFromConnectionString(MicroFour.StrataFrame.Data.DataLayer.DataSources(0 ).ConnectionString))
$
            wrdApp =新Microsoft.Office.Interop.Word.ApplicationClass()"的CreateObject(QUOT; Word.Application")

            使用wrdApp

                .Visible = chkWordVisible.Checked

                .Options.CheckGrammarAsYouType = False

                .Options.CheckGrammarWithSpelling = False

                .Options.CheckSpellingAsYouType = False

                .Options.ContextualSpeller = False

           结束与$
           wrdDoc = wrdApp.Documents.Open(documentname)

          Dim connectionstring As String = String.Format("Provider=SQLNCLI10;Server={0}; Data Source=Alarm64; Uid=?; Pwd=?;", GetServernameFromConnectionString(MicroFour.StrataFrame.Data.DataLayer.DataSources(0).ConnectionString))
            wrdApp = New Microsoft.Office.Interop.Word.ApplicationClass() 'CreateObject("Word.Application")
            With wrdApp
                .Visible = chkWordVisible.Checked
                .Options.CheckGrammarAsYouType = False
                .Options.CheckGrammarWithSpelling = False
                .Options.CheckSpellingAsYouType = False
                .Options.ContextualSpeller = False
            End With
            wrdDoc = wrdApp.Documents.Open(documentname)

            wrdDoc.MailMerge.MainDocumentType = Word.WdMailMergeMainDocType.wdFormLetters

            wrdDoc.MailMerge.OpenDataSource(" C:\users \ Geoff.office \documents\ my data sources \ SERVER1 database.odc",SubType:= Word.WdMergeSubType.wdMergeSubTypeOther)',SQLStatement:= String。格式("从'客户'WHERE ID ='{0}'"选择
*,Customer1.ID))

            wrdDoc.MailMerge.MainDocumentType = Word.WdMailMergeMainDocType.wdFormLetters
            wrdDoc.MailMerge.OpenDataSource("C:\users\Geoff.office\documents\my data sources\SERVER1 database.odc", SubType:=Word.WdMergeSubType.wdMergeSubTypeOther) ', SQLStatement:=String.Format("Select * from 'Customer' WHERE ID='{0}'", Customer1.ID))

      ;       'wrdApp.Dialogs(Word.WdWordDialog.wdDialogMailMergeRecipients)。显示(1000)'这是因为单词中的另一个错误而被试用。

            如果wrdDoc.MailMerge.DataSource.FindRecord(Customer1.ID," ID")=真,那么

          &NBSP ;    使用wrdDoc.MailMerge为
                    .Destination = Word.WdMailMergeDestination.wdSendToNewDocument

                     .SuppressBlankLines =真

                    .Execute(False)

               结束与$
          结束如果

            'wrdApp.Dialogs(Word.WdWordDialog.wdDialogMailMergeRecipients).Show(1000) 'this was trialled because of another bug in word.
            If wrdDoc.MailMerge.DataSource.FindRecord(Customer1.ID, "ID") = True Then
                With wrdDoc.MailMerge
                    .Destination = Word.WdMailMergeDestination.wdSendToNewDocument
                    .SuppressBlankLines = True
                    .Execute(False)
                End With
            End If

我希望合并的单词文档已经准备好并填充了大约6个字段。我在.findrecord行上有一个断点,当findrecord执行时,mailmerge recordcount中有4126条记录返回true,
但记录计数中仍有4126条记录。如果代码进行到执行,短时间过去然后一个有用的COM异常与文本

My word document that I wish to merge with has been prepared and populated with around 6 fields. I have a breakpoint on the .findrecord line and at the point there are 4126 records in the mailmerge recordcount when the findrecord executes it returns true, but there are still 4126 records in the recordcount. If the code progresses as far as the execute, a short time passes then a useful COM exception with the text

"Word无法将主文档与数据源合并,因为数据记录是空的或没有数据记录与您的查询选项匹配。"

"Word could not merge the main document with the data source because the data records were empty or no data records matched your query options."

我发现此消息既麻烦又令人困惑,数据记录显然不是空的,我不确定查询选项意味着什么,据我所知,这都是在.odc文件中设置的。我已经在这个问题上追逐自己了,这应该是非常容易的,并且在其他产品中,充满了陷阱,误导性的消息和迟钝的语法。

I find this message both obtuse and confusing, the data records are obviously not empty and I am unsure what it means by query options, as far as I can tell this was all set up in the .odc file. I have chased myself on this one and something that should be very easy, and is in other products, is filled with pitfalls, misleading messages and obtuse syntax.

如果这是道歉是在错误的地方,因为我使用Word对象,似乎最知识渊博的人会在这里。如果文本听起来有点愤怒,但今天已经花费了18个小时,从一个糟糕的错误消息转到
另一个截止日期即将到来时,也会道歉,这会让人感到有些压力。

Apologies if this is in the wrong place, as I am using Word objects, it seem like the most knowledgable folks would be in here. Also apologies if the text sounds somewhat irate but having spent 18 hours on this today, going from one poor error message to another when deadlines are looming does stress one out a tad.

提前感谢解决方案。

SYM

 

推荐答案

这看起来可能是代码缺陷 - 在2007年,我可以在2010年重现。
This looks like it could be a code defect - in 2007 and I can reproduce in 2010.


这篇关于Word无法将主文档与数据源合并,因为数据记录为空或没有与查询选项匹配的数据记录。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆