Activating Word from within Access

A

Anita Weiler

I have successfully created code to start Word and create
a new document from within Access (code is below).
However, if Word is already running, this code starts a
new instance of Word. How can I check if Word is already
running and activate the existing instance?

The code I'm using is:

Dim wordApp As Object
'Start Word and make it the active window
Set wordApp = CreateObject("word.application")
wordApp.Visible = True
wordApp.Activate
wordApp.Documents.Add
 
P

Phil Hunt

Dim appWord As Word.Application
Set appWord = GetObject(, "Word.Application") ' get the running
instance
If Err.Number = 429 Or Err.Number = 91 Or Err.Number = 462 Then
Err.Clear
Set appWord = GetObject("", "Word.Application") ' not there, create
a new instance
ElseIf Err.Number > 0 Then
MsgBox Err.Description
Exit Sub
 
A

Albert D. Kallal

The trick is to use GetObject(,"word.appliction") first, if word is NOT
running, then you trap the error, and use CreateObject.

I have nice working example of a template driven word merge system. It
automatically takes your current ms-access form, and adds all the merge
fields to the word document. It also by default merges ONLY the record you
are looking at.

So, basically the whole process of creating a word merge template is
automated for you.

Check out:
http://www.attcanada.net/~kallal.msn/msaccess/msaccess.html
 

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