View Single Post
  #4   Report Post  
Peter Jamieson
 
Posts: n/a
Default

You say save without a connection to the data source, how do I do that?

In VBA, use

ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument

If
I remove the data source won't I lose the merge definition, what goes
where?


You will lose the information about the source file or database, and any
sort or filter information, and propably the "current preview record" which
Word seems to save when it is connected to a data source.

To apply sorts and filters programmatically, you have to work out what SQL
is needed, e.g.

SELECT * FROM something WHERE x = 'abc' ORDER BY 1 ASC

or whatever. The only thing this misses is that there is another mechanism
for filtering records in Word 2002/2003 which is to select/reject individual
records in the Merge Recipients dialog box. That kind of filtering is not
implemented using SQL - Word just tries to remember enough info. about each
record to be able to apply the criteria. I recommend that you stay away from
that stuff.

Peter Jamieson

"MCubitt" wrote in message
...
Thanks Peter. In fact I already use VBA to obtain current docpath and
then
dictate the source, but Word errors before VBA is reached, since the merge
seems to be validated upon opening.

You say save without a connection to the data source, how do I do that?
If
I remove the data source won't I lose the merge definition, what goes
where?

Thanks


"Peter Jamieson" wrote:

You can use VBA to get the path name of the .doc and use it to construct
the
path name of the .txt, then issue an OpenDataSource call in an AutoOpen
macro to open that data source when the document opens. However, you
should
also make sure that the document is saved without a connection to the
data
source, and that means that you will lose any sorting or filtering and
you
will need to specify the appropriate bit of SQL in the OpenDataSource
call.

e.g., your macro might be along the following lines (I haven't tested
this
one and you will probably need to modify the OpenDataSource):

Sub autoopen()
Dim sDSFN As String
sDFSN = "data.txt"
With ActiveDocument.Mailmerge
' Change the document type to the one you want
.MainDocumentType = wdFormLetters
.OpenDataSource _
ActiveDocument.Path & "\" & sDFSN, _
SQLStatement:="SELECT * FROM " & sDFSN
' Change the destination to the one you want
.Destination = wdSendToNewDocument
' Uncomment the next line if you want to do the merge
.Execute
End With
End Sub

Peter Jamieson

"MCubitt" wrote in message
...
I have created a merge in MS Word which uses a text file as its data
source.

When I start the document, and review the merge details, it shows the
Data
Source as Data: C:\folder1\data.txt

However, I want to transport the Word and data.txt file which could end
up
on another drive/folder location (but always with the Word and data.txt
in
the same place, not separated).

What I really want is Data: ..\data.txt so it looks inside the current
folder.

Is this possible please?