Clearing Merge Data Source and Merge FIle

S

Shane Buchholz

I have created a Word document that pulls data from a database, writes
that data to a text file and then uses that file as the datasource for
a mail merge. I have set the code up to delete and recreate the source
file whenever the form is run so that I only get current data. The
form is doing what I want it to, save one thing: the source file
becomes associated with the main document during the merge process. If
I try to run the form again to get new data, I get a "permission
denied" error when the code tries to delete the old source file.

Does anyone know how to disassociate the source file from the main
document in VBA. I can do it manually, but I am going to release this
to a non-technical user and I would like the process to be seamless.
The "manual way" is to close the document, delete the source file and
then re-open the document. At this point Word tells you the source
file no longer exists and gives you the option of removing the
data/header source. I created a macro to record the steps when I
re-open the file, and remove the data/header information but that was
not helpful. Thanks in advance.

Richard O'Neil
 
D

Doug Robbins

Probably:

ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 

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