Just recently, one of my clients needed the ability to automatically generate letters to a select list of customers from their custom CRM program - which is a .NET Windows application written in C# with a SQL Server database. Instead of creating a SQL report (which is difficult to maintain); the idea came to me to use Microsoft Word mail merge. However, this meant that I was in need of finding a way to accomplish this using code.
I found several articles (like this one from Microsoft) that showed how to automate the mail merge, including how to create a data source and a form letter from scratch. But since I would already have the data and would simple reuse the same form letter each time, I needed to find a way to open an existing data source and the form letter from code.
After a little more digging, experimenting, and tweaking - I was able to discover a simple, effective way to do so. I've outlined this solution in the following article (the first one I've written in a couple of years - and my first ever programming article):
How to Automate a Mail Merge from Microsoft Word 2003 Programmatically in .NET
One of the things I learned about configuring mail merge data sources in a ODC file is that you can't use a SQL query to sort or filter you data result; you can only specify a table. Not a big deal, I just used a view instead that sorts and filters the data for me.
Happy Programming ... and Happy Cinco de Mayo!