This tip demonstrates how to attach the DB source and populate fields from table to a mail merged word document in VB.NET. |
Code Snippet Dim objWord As New Object objWord = CreateObject("Word.Application") ' Creating a word application Dim objDoc As New Object objDoc = CreateObject("Word.Document") ' Creating a word document object objWord.application.WindowState = 0 ' set the word window in normal state (Const wdWindowStateNormal = 0) objDoc = objWord.Documents.Add(DocsFolder.FullName & "\YOUR WORD DOC NAME") ' Add the mail merged document file Dim NameBeforeWordMerge As String = objWord.ActiveDocument.Name objWord.ActiveDocument.MailMerge.OpenDataSource("YOUR DATABASE PATH", _ Connection:="dsn=DSN NAME; dbq=" & YOUR DATABASE PATH & ";", _ sqlstatement:="select * from `" & tableName & "`") |
Loading
Replies
Know the answer? Post it — somebody with the same question will find it here.