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

Tip: Looking for answers? Try searching our database.

Ralative path for data source

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
SHKDXB - 26 Nov 2007 03:25 GMT
hi anybody can help me to make the path of the data source as relative?. when
trnasporting the files to other machines, i have problem of missisng data
soure - due to absoulte path in the main mail merge documnet. is there a way
to change this data source to relative path??
Peter Jamieson - 26 Nov 2007 10:02 GMT
> is there a way
> to change this data source to relative path??

Not easily - you have to use code, e.g. Word VBA.

First, before you distribute the solution, ensure that the Mail Merge Main
Document has been disconnected from its data source. You have to do that
because nothing you do in VBA can change the data source path /before/ Word
tries to open it.

You can disconnect the data source while the mail merge main document is
open by using

ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument

in the Word VBA Editor Immediate WIndow.

Then, in Word VBA, create an ordinary module in your Document and put a
routine such as the following in it - this assumes that you know the name of
the .xls and that it will be in the same folder as the .doc

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

' set this to be the file name of your data source
strDataSource = "myexcelfile.xls"

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

' set this to be the query for your data source
' if you need to sort aor filter, you need to add
' the appropriate ORDER BY and WHERE clauses
' strQuery = "SELECT * FROM [myrangename]"

With ActiveDocument
 strDataSource = .Path & "\" & strDataSource
 With .MailMerge
   .OpenDataSource _
     Name:=strDataSource, _
     SQLStatement:=str
   ' 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

Unfortunately, you, or your user, will probably also have to take account of
the following artiicle:

http://support.microsoft.com/kb/825765/en-us

Signature

Peter Jamieson
http://tips.pjmsn.me.uk

> hi anybody can help me to make the path of the data source as relative?.
> when
> trnasporting the files to other machines, i have problem of missisng data
> soure - due to absoulte path in the main mail merge documnet. is there a
> way
> to change this data source to relative path??
SHKDXB - 27 Nov 2007 02:54 GMT
Thanks for the info
couldn't understsnad the line

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

tried but getting error as "compile error argument not optional" str
highlighted in statemnet SQLStatement:=Str
any help?

> > is there a way
> > to change this data source to relative path??
[quoted text clipped - 60 lines]
> > way
> > to change this data source to relative path??
Peter Jamieson - 27 Nov 2007 09:17 GMT
Yes, there are some errors in the code. What you need depends partly on the
data source, but...

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

' set this to be the query for your data source
' if you need to sort or filter, you need to add
' the appropriate ORDER BY and WHERE clauses
strQuery = "SELECT * FROM [myrangename]"

With ActiveDocument
 strDataSource = .Path & "\" & strDataSource
 With .MailMerge
   .OpenDataSource _
   Name:=strDataSource, _
   Connection:=strConnection, _
   SQLStatement:=strQuery

and so on...

Signature

Peter Jamieson
http://tips.pjmsn.me.uk

> Thanks for the info
> couldn't understsnad the line
[quoted text clipped - 77 lines]
>> > way
>> > to change this data source to 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.