Possible to get Word Mail Merge data source from VB6?

J

Jim Lin

Is it possible to find out what data source a Word template is pointed to
from VB6? We currently have groups of people we want to send letters to,
multiple types of letters we can send, and a single Access file (*.mdb) with
different views into the data (populated via a server call). Our current
(hack) error detection scheme is to go ahead and try to execute the mail
merge, then catch the error 5631* if the template is the wrong type for the
person's group.

I'd like to be able to ensure there is data for a particular view before
trying to do the mail merge, but need to find a way to figure out what view
the template is set to use. Is this possible?

Jim


* - Error 5631: Word could not merge the main document with the data source
because the data records were empty or no data records matched your query
options.
 
G

Greg Ellison [MS]

Hello Jim,

Have you tried the DataSource object, For example:

Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Open("c:\mydoc.doc")
MsgBox oDoc.MailMerge.DataSource.Name
MsgBox oDoc.MailMerge.DataSource.QueryString
MsgBox oDoc.MailMerge.DataSource.TableName

For information and sample code for integrating Office with Visual Basic,
Visual C++, Internet Scripts, and other programming languages, please see
http://msdn.microsoft.com/library/techart/VSOfficeDev.htm. This site
contains the most up-to-date information for using developer tools for
Office integration and extensibility.

Best regards,
Greg Ellison
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? For information about the Microsoft Strategic Technology
Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.

--------------------
 

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