Access doesn't release Word doc after opening it
Posted on 2011-09-23
Hello, I have a pretty simple function in my database that just opens a word doc when a field is double clicked on, but the problem that I'm running into is that the document cannot be edited and saved when launched this way, or word gives the error message "... is currently in use. Try again later".
I've tried three different methods:
1.) Shell command... I've gone back to this, even though I had reliability problems with this before:
Shell "WINWORD.EXE """ & Trim(LWordDoc) & """", vbNormalFocus
2.) Late binding; this is the preferred method, I believe, as it can survive changes in the Word version without having to recompile or make special cases; we have a couple of old computers floating around that still have office 2003 on them, so this is kind of important
Dim oApp As Object
'Create an instance of MS Word
Set oApp = CreateObject("Word.Application")
'Open the Document
oApp.Visible = True
Set oApp = Nothing
3.) Early binding; I set this up from examples, just to see if it would release the document properly after the word objects were destroyed, but it was no better:
Dim doc As Word.Document, wrdApp As New Word.Application
Set doc = wrdApp.Documents.Open(LWordDoc)
wrdApp.Visible = True
'If you are just opening the doc then release the window
Set doc = Nothing
Set wrdApp = Nothing
It seems to me that, aside of early binding issues, either method 2 or 3 should work just fine, but in my production environment, you cannot edit and save changes to the documents launched by those functions unless you pick a new file name, which means that for some reason, Access is not fully releasing the word objects, and thus those files are still locked.
Does anybody have any insight on this?
Thanks in advance,