none
Word Inter-op - Mail Merge

    Question

  • I have an existing mail merge word document (docx). This is a docx was once a 2003 document(.doc) file. Now it is a docx file in compatibility mode.

    My mail merge document already has a data source that comes from an ms-access database e.g. C:\Sales.accdb.  The datasource come from a table called Orders.  When you open the word document the dialog box comes up with Select * FROM 'Orders' etc, etc...

    All OK so far.  Now what I want to do is via C# VS using the word inter-op, is some how change only the data source e.g to D:\SalesAust.accdb.  I don't want anything else to change.  I need this because I have about 100 letters in a production environment and I want to set up a UAT environment.  I thought the best way to do this is to be able to just change the data source through a property.

    Eagerly awaiting your response.


    Friday, March 31, 2017 5:33 AM

Answers

  • AFAIK, you can't just change the data source. The MailMerge DataSource property is read-only so you have to use OpenDataSource to specify all of the necessary parameters for the mail-merge.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, March 31, 2017 11:05 PM

All replies

  • Have you tried using the OpenDataSource method of the MailMerge object?

    http://blog-dotnetsp.blogspot.com/2010/02/automation-of-mail-merge-from-windows.html


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, March 31, 2017 11:45 AM
  • In answer to your question Yes.

    The OpenDataSource method assumes you want to mail merge with a new datasource.  You have to specify the datasource your self along with the type of merge and the query/table you want to deal with.

    However, in this situation I want to keep the mail merge type and the query/table the same, I only want to modify (in this case) the database name.  So currently as specified above with an existing document my datasource would be Database: C:\Sales.accdb, Table or query would be 'Select * from Orders' and the mail merge type would be Letters.  I want to get to the property that only changes the Database name.  So C:\sales.accdb becomes D:\SalesAust.accdb.  I am asking how to do this using MailMerge object via C#.  How can I get back whats is already there and change the properties?

    Friday, March 31, 2017 10:03 PM
  • AFAIK, you can't just change the data source. The MailMerge DataSource property is read-only so you have to use OpenDataSource to specify all of the necessary parameters for the mail-merge.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Friday, March 31, 2017 11:05 PM
  • Sorry for the belated reply.

    Thank you.  I will take your advise and formulate a solution.

    Thursday, May 16, 2019 9:41 AM