Mailmerge works for me but not my client!

R

rustle

I am vexed at why the code below sometimes works and sometimes doesn't. I
developed the application on my PC and then transferred it to the client's
PC. On his PC are 2 user accounts - one I use for maintenance and the
client's. Both are full admin accounts (not my decision!). If I run the app
with me logged on it works fine. If I run it with him logged on it fails at
this line shown. If I open the master document with Word from his user
account it opens and merges successfully.

The circumstances at failure are strange. There is an error message (as
shown in comment above the line which fails). It's format is what results
from the "Err_ZZZ" code at the bottom - even if I put <On Error Goto 0>
immediately above the offending line! Of course this could be triggering the
error trap from a routine somewhere else in my code as I use this type of
error trap everywhere - but this looks like a bug in Access / Word.

My conclusion is that opening Word has caused the application to misbehave.
However I am at a loss as to how to find the cause and fix it. Any ideas
gratefully received.

By the way, I am appalled at the really clumsy way Word and Access interact.
I want to avoid the client having to mess with the mailmerge in Word so I am
trying to do this within my Access application. When the mailmerge letters
are created I then close Access and let him click on the merged letters
(saved on his desktop) so as to use Word to print them (or if he wants to
edit some of them first). If anyone has a suggestion as to how to do this
better please advise.

I'm not entirely comfortable with my solution as when it runs ok, the
invocation of Word from within my Access database code opens another instance
of the database to get the query data. Not really a prbblem but it seems
crude.

Russell Gadd




Public Sub MergeLetters(strMergedLetters As String)
On Error GoTo Err_ZZZ

Dim objMSWord As New Word.Application
Dim objMasterDoc As Word.Document

'The filenames below are valid
Set objMasterDoc = objMSWord.Documents.Open(strMailMergeDocsPath &
strMasterDocName)

'note that this doc has already got the record source defined as the
correct query in the database
'and has been saved immediately after a successful merge
'I just want to reopen it with the query reflecting new data

'LINE BELOW FAILS with message - This method or property is not available
because the document is not a mail merge main document
'(I can assure you it is and works when run by a different user!)
objMasterDoc.MailMerge.Execute

objMSWord.Application.Documents(1).SaveAs (strMergedLetters)

'close the merge MasterDoc without saving
objMasterDoc.Close wdDoNotSaveChanges

Exit_ZZZ:
objMSWord.Application.Quit
Set objMSWord = Nothing
Set objMasterDoc = Nothing
Exit Sub
Err_ZZZ:
MsgBox Err.Description & vbCrLf & "Error number " & Err.Number
Resume Exit_ZZZ
End Sub
 
R

rustle

Have fixed this now myself. I discovered the fix in KB825765 which requires a
registry modification. In fact I had already done this before for my
maintenance account but failed to document it properly and forgot I had done
it! Easy moral to this story - make good notes of all you do!
 

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