View Single Post
  #5   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Don
 
Posts: n/a
Default .ActiveDocument.mailmerge Syntax sometimes not working

Thanks for the help, this is an issue when using Word 2003.
Seems like the security on Word 2003 drops the linked datasource when opened
so I did have to reset the datasource to the text file I use.

ActiveDocument.MailMerge.OpenDataSource "Path&FileName"

"Peter Jamieson" wrote:

OK, so it never fails at the point when you set the destination. In that
case nothing springs to mind, but
does it fail if you set the Destination to be 1 (Send to printer) ? If not,
then I suppose I would start looking for some reason why Word could not open
a temporary document, e.g. perhaps there is a security-related issue on some
machines.

( This is probably nothing to do with the problem but I wouldn't use
ActiveDocument in case something else was being opened for some reason, and
would use something more like...

Dim objApp As Object
DIm objDoc As Object ' or As Word.Document
Dim strDocName As String
'Dim strDocNameB As String
'strDocName = rs!ClosingDir & "\MasterTest.doc"
strDocName = rs!ClosingDir & "\" & rs!ClosingDoc
Set objApp = CreateObject("Word.application")
objApp.Visible = True
set objDoc = objApp.Documents.Open strDocName
'strDocNameB = objDoc.Name
objDoc.mailmerge.Destination = 0 'wdSendToNewDocument
objDoc.mailmerge.Execute
objDoc.Close 0
set objDoc = Nothing
)

Peter Jamieson

"Don" wrote in message
...
The main document is linking correctly to the text file that I have it set
to. I have looked at the main document(mailmerge document) and the values
are being pulled from the text file. I just get an error message when
trying
to execute it into a new document.

"Peter Jamieson" wrote:

An attempt to set .Destination will fail if there is no data source.
Since
there is no OpenDataSource method call in the code you have posted, my
guess
is that you have attached the word document to a data source, then closed
it. That's fine, unless Word cannot re-attach the document to the source
when it re-opens the document, and that could happen for various reasons,
e.g. the data source is not where Word expects to find it, or some users
are
using a different Word version or Service Pack from others. Ther are a
couple of things you could try to find out what is gong on:
a. add error trapping to your Access code, if you haven't already
b. ask 1 user whose system works and 1 user whose system doesn't to open
the datasource manually, and see what happens.

Peter Jamieson

"Don" wrote in message
...
Hello, I'm using this code below from with Access to open a Word
document.
It works fine on my machine but I have a user that gets an error when
trying
to run the mailmerge.execute line. Any thought why?

Dim objApp As Object
Dim strDocName As String
Dim strDocNameB As String
'strDocName = rs!ClosingDir & "\MasterTest.doc"
strDocName = rs!ClosingDir & "\" & rs!ClosingDoc
Set objApp = CreateObject("Word.application")
With objApp
.Visible = True
.Documents.Open strDocName
strDocNameB = objApp.ActiveDocument.Name
***Lines Below sometimes don't work on other machines.
.ActiveDocument.mailmerge.Destination = 0 'wdSendToNewDocument
.ActiveDocument.mailmerge.Execute
.Documents(strDocNameB).Close 0
End With