Solved

Running Word Mail Merge from Access opens 2 emtpy instances of Word

Posted on 2016-10-28
3
26 Views
Last Modified: 2016-10-28
Hello - I'm having a problem running Word mail merge from Access, using the code below. This routine is kicked off from a command button; when the users click this button the 1st time, 2 empty instances of Word appear, with no template doc or mail merge result doc in either one. Then they click the button a second time, and a 3rd instance of Word comes up, with the mail merge result doc.

What's really driving me crazy is that *I* am not having the problem when I run on my pc, but all the users are.

I will admit to not knowing how to reference the original application instance, as opposed to the mail merge result instance. So when I close the original instance, and make the result instance visible, I might not be doing that in the best way. But why would it have the problem on the 1st execution, and not the 2nd?

Everybody is running Office 2003 on Windows 7; some (me included) have 4GB RAM, most only have 2GB, but even the 4GB users are having this problem.

JUST NOW >>> one user just told me that he does not have the 2 instances problem when he closes Outlook before running the mail merge. This makes sense because they all have their Outlook message editor set to use Word, and I don't. If this is the problem, is there a work-around?

Thanks

The code:
'-- code before here strings together the Word mail merge templates folder path with the template file name, resulting in "strDocFullLoc"
Application.Echo True, "Starting Word..."
Set objWordApp = CreateObject("Word.Application")

Application.Echo True, "Opening mail merge template..."
Set objWordDoc = GetObject(strDocFullLoc, "Word.Document")

Application.Echo True, "Starting Mail Merge..."

'-- execute the merge
objWordDoc.MailMerge.Destination = wdSendToNewDocument
objWordDoc.MailMerge.Execute Pause:=False

'-- close the merge template (leaves the merge result doc open), show Word
Application.Echo True, "Closing mail merge template..."
objWordDoc.Close True
objWordApp.Visible = True

MsgBox "Mail Merge Complete", vbOKOnly, strMBTitle
0
Comment
Question by:mlagrange
3 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 41863990
How does this work?
Const wdSendToNewDocument = 0

Dim objWordApp As Object
Dim objWordDoc As Object

    Application.Echo True, "Starting Word..."
    Set objWordApp = CreateObject("Word.Application")

    Application.Echo True, "Opening mail merge template..."
    Set objWordDoc = objWordApp.Documents.Open(strDocFullLoc)

    Application.Echo True, "Starting Mail Merge..."

    '-- execute the merge
    objWordDoc.MailMerge.Destination = wdSendToNewDocument
    objWordDoc.MailMerge.Execute Pause:=False

    '-- close the merge template (leaves the merge result doc open), show Word
    Application.Echo True, "Closing mail merge template..."
    objWordDoc.Close True
    objWordApp.Visible = True

    MsgBox "Mail Merge Complete", vbOKOnly, strMBTitle

Open in new window

0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 41863993
try commenting this line

Set objWordApp = CreateObject("Word.Application")

post back the result
0
 

Author Comment

by:mlagrange
ID: 41864230
Norie - that worked! Just the difference in that 1 doc open method?!
Rey - your suggestion worked as far as the merge, but I wasn't able to close the template and just show the mail merge result like I wanted.

Thank you both for your help
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now