MySQL Mail Merge with Microsoft Word
Connected to the last entry, using MySQL from Microsoft Word can be fairly easily achieved without all the faffing of exporting data from MySQL and importing it into Access. It's something that one of my clients required having used a web-page to gather information into a MySQL database, and then requiring the output of a number of letters based on this data. It requires the installation of the MySQL ODBC driver which Word is then able to access through the mail merge wizard.
So, here's what to do:
- Get the latest MySQL ODBC driver from the MySQL site: http://dev.mysql.com/downloads/connector/odbc - the MSI installation is probably the easiest.
- Install the ODBC Driver.
- Go to Control Panel > Administrative Tools -> Data Sources (ODBC)
- Make sure the "User DSN" tab is selected and click the "Add..." button
- Select from the list "MySQL ODBC 3.51 Driver" and click Finish.
- A box will appear. In the Login Tab, give the Data source a name and description (these are up to you).
- Enter the information for your MySQL server the boxes.
- Click OK, and you're done setting up the database connection.
To use this in Word's mail merge, you need to do the following:
- Tools > Letters and Mailings > Mail Merge Wizard
- Select Document Type, click Next
- Select Starting Document, click Next
- Select "User an existing list" and click "Browse..."
- Select "+Connect to New Data Source.odc"
- Select "ODBC DSN"
- Select the data source by the name you gave it above
- It will show you a list of the tables in that database. Select the table you want to get data from and give this a description if you feel like it, although you can just leave it if you want.
- Click Finish.
- A box will pop up.
- This bit is important, otherwise it won't work:
Number 3 says: "Enter the initial catalog to use"
Click the drop down box, and then click off the drop down box.
The box should be empty! - The "Test Connection" button should now work.
- Click ok, and you're taken back to the mail merge wizard showing a list of the people in the database.
You can now use this as you would any mail merge.
9 Comments:
Sounds like a great idea. Are you saying you can filter the data as normal by any value in any of the table fields too? If so it would save a whole heap of time ... all the exporting (I do this as a csv) and bunging it into a file on the local drive and everything ... food for thought.
6:43 PM
Hi, thanks for this, it was a lifesaver to me! All I need to do now is work out how to get multiple tables into the mailmerge!
Thanks
11:53 PM
Create a View !
3:16 AM
I am trying to connect to a remote server (on my webhost) I can't figure out what to put in the server box in setting up the ODBC source.
7:04 PM
I am working with word 2003 Mail Merge.
I am unable to connect MySQL DB on remote as well as local server.
Eventhough i have installed the mysql connector 5.0 on my system.
please, plaese help me.
Thanks in Advance.
Salil
12:28 PM
Hi.
infinity: In the server box you should just put the name of the machine on which the MySQL server is residing, mymachine.mydomain.com.
dmcmech2004: It sounds like you've installed the MySQL Connector/J 5.0, if so that's the wrong thing. The link in the post goes to the ODBC installer (latest version is 3.51.16 at time of writing). Is this what you tried? I think the instructions above still work.
10:15 PM
Great tutorial, thanks for giving this information - you just saved me days of work...
11:15 AM
The initial catalog setting was a killer for me. I have spent hours working on finding a solution any you were my saving grace. Thank you.
3:10 AM
I've tried this with Word 2000 and find that I get stuck when I try to link through with the Mail Merge Wizard. Is this because it's an old version of WORD?
Steve
9:44 PM
Post a Comment
Links to this post:
Create a Link
<< Home