Word 2002 Mailmerge using data from MySQL

P

Phillip Dade

Hi

I have been trying to set up a mail merge using data within a mysql database
and using an ODBC connection. I have succeeded in setting this up and all
'test' connections are working fine, however when I click 'ok' within the
'connection' tab of the data link properties; I get a prompt appear entitled
Mail Merge with the following statement contained within: 'Record 1 contained
too few data fields' this repeats itself through each row of the database.
Does anybody know of a way around this? I have tried the same set up using
Open Office and that seemed to work.
 
P

Peter Jamieson

If you're seeing the data link properties, you're probably actually
connecting via OLE DB, using the OLE DB provider for ODBC data sources, and
in my experience Word doesn't usually work with that very well.

In this case it's probably going to be easier doing the connection using
VBA, in which case you need something like the following if you're using a
system or user DSN:

Sub Connect2mySQL()

ActiveDocument.MailMerge.OpenDataSource _
Name:="", _
Connection:="DSN=your mySQL ODBC dsn name;PWD=your mySQL password;", _
SQLStatement:="SELECT * FROM mytable", _
SubType:=wdMergeSubTypeWord2000

End Sub

or like the following if you're using a file DSN:

Sub Connect2mySQL()

ActiveDocument.MailMerge.OpenDataSource _
Name:="the full path name to your .dsn file", _
Connection:="FILEDSN=the full path name to your .dsn file;PWD=your mySQL
password;", _
SQLStatement:="SELECT * FROM mytable", _
SubType:=wdMergeSubTypeWord2000

End Sub

You might also need the UID= parameter (mySQL user ID) if it isn't in your
DSN.
You should only need to run the macro once to set up the data source - after
you've saved the document, the connection should be re-made on re-open
(forgetting about the SQL prompt).

If you're not familiar with how to run VBA macros, see

http://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm

Peter Jamieson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top