Trouble with MailMerge from Access Module

J

James P. McNellis

All--

I am having some trouble with a Microsoft Access application that utilizes
Microsoft Word's MailMerge functionality through a VBA module.

Supposively this application worked fine in Office 2000, but I am unable to
locate a copy of Office 2000 on which to test it.

DoCmd.TransferText acExportMerge, "", sPrintTable, sMergeDataFile

The code starts off as follows:

Set WordObj = CreateObject("Word.Application")
WordObj.Visible = False
WordObj.Documents.Open FileName:=sWinWordFile
WordObj.ActiveDocument.MailMerge.Destination = wdSendToNewDocument

That last line there is what causes the error:

Microsoft Visual Basic
Run-time error '5852':
Requested object is not available.

sWinWordFile is a string and I have checked the path and it is the correct
path to the document I want to open. When I debug the module, it states
that WordObj.ActiveDocument.MailMerge.Destination = -1.

The code continues as follows, just to give context to the above code:

WordObj.Documents(sWinWordFile).MailMerge.Execute
WordObj.ActiveDocument.SaveAs FileName:=sMergedFile

Does anyone have any suggestions? I've been trying to figure this out for
over a week, to no avail.

Thanks in advance, both for taking the time to read my post, and for helping
to find a solution. I sincerely appreciate the efforts of these Microsoft
newsgroups.

Sincerely,

James McNellis
 
T

TC

James, I can't really give you an answer, because I don't have that
version of Word here either.

But here are some things you could try.

(1) Make the instance visible (not invisible) and put msgboxes in the
VBA code between each step. Then you can swap back & forth between the
Access msgbox, and the (visible) Word screen, to sight-check what is
going on. Maybe you'd see a greyed-out toolbar option, or somesuch,
which might provide a clue.

(2) I know that MS have occasionally made significant changes to the
mailmerge object model. You don't say what version of word you were
using to test it (unless I missed that). So if the app was devloped for
word 2k, and you are testing in word 97, that would cerainly explain it
IMHO.

HTH,
TC (MVP Access)
http://tc2.atspace.com
 
C

Cindy M -WordMVP-

Hi James,

I'm guessing you're dealing with a security-thingy introduced in the
last couple of years. See if this applies:

"Opening This Will Run the Following SQL Command" Message When You
Open a Word Document - 825765
http://support.microsoft.com?kbid=825765

It boils down to:
Word is unlinking the data source when a mail merge document is
opened programmatically. you have to either
- create the Registry key to turn off the security
OR
- link the data source back in in your code (OpenDataSource
method)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 

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