Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / April 2007

Tip: Looking for answers? Try searching our database.

Word 2002 Mailmerge using data from MySQL

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Phillip Dade - 11 Apr 2007 14:08 GMT
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.
Peter Jamieson - 11 Apr 2007 19:29 GMT
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

> Hi
>
[quoted text clipped - 9 lines]
> Does anybody know of a way around this? I have tried the same set up using
> Open Office and that seemed to work.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.