some word documents are missing datasource for mailmerge

interwanderer

New member
Joined
May 26, 2009
Messages
2
Programming Experience
3-5
Hello everyone,

I have quite a lot of word documents that try to complete a sql command when opening so that they can do mailmerge. Unfortunately some of those documents don't have a datasource and a mailmerge doesn't happen.
I'm trying to find out wich of those documents have this problem.
Unfortunately when I'm open a document thru code the sql statement does not happen and a mailmerge also doesn't happen. And because of this I can't check if this document has a datasource.

Can anyone help please?

the code below seems to work to open the document but the mailmerge is no longer shown and thus I cannot check if there is a datasource or not. There never is.
Maybe there is a parameter that i can give to the open statement so that i can let the mailmerge happen as it should?


Dim wordApp As New Microsoft.Office.Interop.Word.ApplicationClass()
wordApp.Visible = True

'Interop params
Dim oMissing As Object = System.Reflection.Missing.Value
Dim save As Object = False

docFile = "C:\mdo\2009\doc1.docx"

Dim wordDoc As Microsoft.Office.Interop.Word.Document = wordApp.Documents.Open(docFile, oMissing, [readOnly], oMissing, oMissing, oMissing, _
oMissing, oMissing, oMissing, oMissing, oMissing, isVisible, _
oMissing, oMissing, oMissing, oMissing)
 
Perhaps you can check doc.MailMerge.Fields.Count ? With the idea that all merge documents has merge fields and all non-merge documents don't...
No data source is loaded with automation until you call OpenDataSource method.
 
Thanks for answering. Seems that a security check of office doesn't allow sql statements to be executed. by changing a value in the registry everything seems to work fine.

kind regards.
 
Back
Top