creation of a document based on mailmerge template

L

Licinio

I have a mailmerge template whose source is a query in access. I need
to create a new .doc document based on that .dot template and still
connected to the data source. The attempts I have made in visual basic
have led to either:
- the opening of the .dot template actually connected to the data
source, but unsuitable for use because the user may inadvertently save
changes; or
- the creation of a .doc document based on the .dot template, but not
a mailmerge document and so not connected to the source data.
What instructions shoud I use?
Thanks.
 
D

Doug Robbins - Word MVP

Using the following code will attach the data source to a document created
from a .dot template that has the data source attached to it to the
document:

Dim source As String, dsource As String
Dim sourcedoc As Document
With ActiveDocument
source = .AttachedTemplate.FullName
Set sourcedoc = Documents.Open(source)
dsource = sourcedoc.MailMerge.DataSource.Name
sourcedoc.Close wdDoNotSaveChanges
.AttachedTemplate = "Normal.dotm"
.MailMerge.OpenDataSource Name:=dsource
.AttachedTemplate = source
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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