Open Data Source issue when Automating a mail merge

M

Michael Teede

I have a small VB application which automates the
generation of a number of Letters based off a shared data
file. The data file is delimited at the field using ','
and at the record with '~' to allow for carriage returns
to be included within the data.

Originally, the application was run in Win98 using Word97,
with the VB application including a refernce to the
Microsoft Word 8.0 Objects library.

When this was migrated to XP using Word2002, with a
reference to the Microsoft Word 10.0 Objects library, an
error occured when we performed the mail merge. For some
reason, the mail merge is not available until we relink
the data source. When we do this, either manually or
automated, the user is prompted to specify the delimiters,
which is not something that will be accepted by the
business area.

QUESTION - How do we suppress the delimiter dialog window
every time we attempt to open a document and perform a
mail merge?

The sample code is as follows:
Static ObjWord as Word.Application

Set objWord = Nothing
Set objWord = CreateObject("Word.Application")
objWord.Documents.Open "C:\temp\test.doc"
objWord.ActiveDocument.MailMerge.OpenDataSource "c:\temp\te
st.txt"
objWord.ActiveDocument.MailMerge.Destination =
wdSendToNewDocument
objWord.ActiveDocument.MailMerge.Execute

....
 
C

Cindy M -WordMVP-

Hi Michael,

I can't imagine that this actually worked in an earlier
version of Word. In my experience, using anything BUT an
carriage return as the record delimiter is going to pop up
this dialog box. (And I've been working with and supporting
mail merge for over ten years, since Word 2.0.)

The only thing I can remotely imagine is that you might have
had a customized Text ODBC DSN that was allowing this.
(Although I thought it was only possible to designate field,
and not record delimiters in a DSN; but I'm not an ODBC
expert so I may be mistaken about that.)

Note that Word 2002/2003 now use OLE DB as the default
connection, and that's certainly what's being used when you
test your code. IOW, Word probably isn't connecting to the
data in the same way it did before. From the looks of the
code, you were probably using Word's internal text converter,
before. That shouldn't make a difference with this prompt,
but if you want to test:
- Tools/Options/General
- Activate "Confirm conversions on open"
- select the data source file (in the UI)
- now you should be able to choose how Word connects

For reliable results, I recommend you change how the data
source is being generated. If the reason you use a tilde is
because the data might contain Chr$(13), then surround the
data with "quote" or 'apostrophes'. Then Word will correctly
recognize what belongs to the data, and what is a record
separator.
I have a small VB application which automates the
generation of a number of Letters based off a shared data
file. The data file is delimited at the field using ','
and at the record with '~' to allow for carriage returns
to be included within the data.

Originally, the application was run in Win98 using Word97,
with the VB application including a refernce to the
Microsoft Word 8.0 Objects library.

When this was migrated to XP using Word2002, with a
reference to the Microsoft Word 10.0 Objects library, an
error occured when we performed the mail merge. For some
reason, the mail merge is not available until we relink
the data source. When we do this, either manually or
automated, the user is prompted to specify the delimiters,
which is not something that will be accepted by the
business area.

QUESTION - How do we suppress the delimiter dialog window
every time we attempt to open a document and perform a
mail merge?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun
8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 

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