Closing Access

B

Brian Walters

I have a client that I have set up to use a Word merge
with Access queries as the data source. The Access
database actually opens the Word document, through VBA
code, merges and prints the result and then closes Word.
When the Word file is opened, it opens another instance of
Access. We are both using Access97 and WindowsXP.
Everything works great on my end, but the Access data
source is being left open at their place when Word is
closed out. When you try to look at the file, nothing
comes up and you can't delete it from your Taskbar. Does
anyone know why this might be happening? Is there a way I
can, programmatically, search to see if the source file is
opened and then close it?
 
J

Jim/Chris

I got this from a previous post (Merle)
As far as I know you can only do this in VBA, not in a
macro. Here's how
I usually do it. This first bit will grab hold of an
existing instance
of Word or else launch a new one:

Dim oWord As Word.Application
Dim blWordAllMine As Boolean

On Error Resume Next 'handle errors inline
'Get hold of Word if it's running
Set oWord = GetObject(, "Word.Application")
If oWord Is Nothing Then 'need to fire it up ourselves
Set oWord = CreateObject("Word.Application")
If oWord Is Nothing Then 'Failed
MsgBox "Sorry, could not launch Word," & MSG_NEEDED, _
vbOKOnly + vbExclamation, MSG_TITLE
Exit Sub
Else
blWordAllMine = True
End If
Else
blWordAllMine = False
End If
On Error GoTo 0 'reset error handling

Then when your code has finished with Word, you need to
release the
Word.Application object without disturbing an
already-running instance
of Word, something like this:

If blWordAllMine Then
oWord.Quit False
Else
'close any documents your code opened
...
'set the corresponding document objects to Nothing
...
End If
Set oWord = Nothing


Good Luck

Jim
 

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