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 / July 2007

Tip: Looking for answers? Try searching our database.

How do I connect to a mail merge data base using a relative path?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Blackshadow - 10 Jul 2007 05:36 GMT
How do I connect to a mail merge data base using a relative path?
Peter Jamieson - 10 Jul 2007 08:11 GMT
As far as I know you cannot do this without code, e.g. VBA code, because
a. Word always stores the pathnames of data sources as absolute path names
b. in any case, Word treats relative path names as relative to the /active/
folder, which is not necessarily the folder containing the mail merge main
document.

To use VBA to fix the path, you really have to do at least two things:
c. make sure that the Mail Merge Main Document is never saved with any data
source information - otherwise, when you re-open it, the first thing that
Word does is to try to locate the existing data source. You can't write a
macro that intercepts Word before this point and you can't really guarantee
to avoid the dialog boxes that will appear if the data source is not found.
d. use an AutoOpen macro to connect to the new data source

To disconnect a datasource from its datasource before saving it, you can use

ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument

You will lose the source name, connection information and any sort/filter
selections, but not any of the fields in the document.

Here's a sample AutoOpen for you:

Sub AutoOpen()
Dim strDataSource As String
Dim strConnection As String
Dim strQuery As String

' this is a simple example for a data source which is a Word document
' set this to be the file name of your data source
strDataSource = "kt.doc"

' set this to be the connection string for your data source
'strConnection = ""

' set this to be the query for your data source
' strQuery = ""

With ActiveDocument
 strDataSource = .Path & "\" & strDataSource
 ' for a Word document as data source, we just need the path name
 With .MailMerge
   .OpenDataSource _
     Name:=strDataSource
   ' use the type you need
   .MainDocumentType = wdFormLetters
   ' use the destination you need
   .Destination = wdSendToNewDocument

   ' NB the above code does not execute the merge.
 End With
End With
End Sub

When connecting programmatically, you may also have to implement the
registry change described in

http://support.microsoft.com/kb/825765

Peter Jamieson

> How do I connect to a mail merge data base using a relative path?
 
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.