I'm writing a program that takes some simple input from the user via a combo box and a treeview and opens a word document and mail merges the appropriate data from a Microsoft SQL server.
I'm pretty sure I have everything hammered out, except when I run the program I end up with the error that Word was unable to open the data source.
Unfortunatly I have not found a wealth of solid information out on the Internet with regards to office interop. I've had to piece a lot together to get it this far.If anyone has any suggestions as to why it's unable to open the data source with the following code it would be most appreciated.
On a side note, I'd love to know of a good book or reference that shows more of the office interop with VB and .net.
Thanks!
Error:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in VBPorcupineFrontEnd.exe
Additional information: Word was unable to open the data source.
Code:
Code:Dim docPath As String = "C:\porcupine\docs\" Dim wrdApp As New Word.Application Dim wrdDoc As New Word.Document Dim TemplateFile As String = docPath + TreeView1.SelectedNode.Text & ".doc" Dim oMissing As New Object Dim oFile As New Object Dim oSql As New Object Dim oFalse = False Dim oTrue = True Dim ODCFile As New Object ODCFile = "C:\Porcupine\memberdata3.odc" oFile = TemplateFile oMissing = System.Reflection.Missing.Value wrdApp.Visible = True wrdDoc = wrdApp.Documents.Open(oFile, oMissing, oTrue, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing) wrdDoc.Select() Dim wrdMailMerge = wrdDoc.MailMerge oSql = "SELECT * FROM MemberData WHERE MBRNAME =" & ComboBox1.Text wrdDoc.MailMerge.OpenDataSource(ODCFile, oMissing, oMissing, oFalse, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oSql, oMissing, oFalse, oMissing) wrdMailMerge.SuppressBlankLines = True wrdMailMerge.Execute(oFalse) If wrdDoc Is Nothing Then wrdDoc.Saved = True wrdDoc.Close(oFalse, oMissing, oMissing) End If 'If wrdApp Then wrdApp.Quit(oFalse, oMissing, oMissing) 'End If wrdMailMerge = Nothing wrdDoc = Nothing wrdApp = Nothing




If anyone has any suggestions as to why it's unable to open the data source with the following code it would be most appreciated.
Reply With Quote