Solved

Access doesn't release Word doc after opening it

Posted on 2011-09-23
12
240 Views
Last Modified: 2012-05-12
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
        oApp.Documents.Open LWordDoc
        oApp.Activate
        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
        wrdApp.Activate
        '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,

--Jon
0
Comment
Question by:CoastalData
  • 6
  • 5
12 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 36587598

try


        Dim oApp As Object
        'Create an instance of MS Word
        Set oApp = CreateObject("Word.Application")
        'Open the Document
        oApp.Visible = True
        oApp.Documents.Open LWordDoc
        oApp.Activate
       
         oApp.quit       'Add this line

        Set oApp = Nothing



also, before running the codes
open  Task Manager > Processes
select Word.exe and clcik on End Process


0
 
LVL 3

Author Comment

by:CoastalData
ID: 36587630
I tried that... If I add the .quit, then word closes, and the doc is not left open, defeating the purpose...
0
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 36587697
If you just want to open the doc for the user then replace all your automation code with..

Application.Followhyperlink "Pathtodoc"
0
 
LVL 3

Author Comment

by:CoastalData
ID: 36587764
Okay, cool! That worked! I've always felt that the automation method was overkill, but the shell method too hit/miss...

Do you know if that's backwards compatible with 2003?

Have you used this much, are there any shortcomings of it that will haunt me later? LOL
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 36587778
the line

         oApp.quit       'Add this line

will release the word app that was opened from access. you will use that line when doing revision to the word doc using codes

        Dim oApp As Object
        'Create an instance of MS Word
        Set oApp = CreateObject("Word.Application")
        'Open the Document
        oApp.Visible = True
        oApp.Documents.Open LWordDoc
        oApp.Activate
              '
              'codes for automation to revise the doc

         oApp.activedocument.save  ' save the doc

         oApp.quit       'Add this line

        Set oApp = Nothing

Open in new window



if you want to edit the word doc after opening

try this


        Dim oApp As Object
        'Create an instance of MS Word
        Set oApp = CreateObject("Word.Application")
        'Open the Document
        oApp.Visible = True
        oApp.Documents.Open LWordDoc
        oApp.Activate
        

Open in new window

0
 
LVL 3

Author Comment

by:CoastalData
ID: 36587869
Hey Cap,

Your second example is almost identical to my code as originally posted for the late binding example... And, of course, your first example works fine if you're making the changes automatically, but in this case, I just need to open the doc and then leave it there for the user to interact with.
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 119

Expert Comment

by:Rey Obrero
ID: 36587914
did you try the second code ? just tried it and it work.
0
 
LVL 3

Author Comment

by:CoastalData
ID: 36587944
And you can make a change to the opened document and then save it with no errors?
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 36588001
Yes
0
 
LVL 3

Author Comment

by:CoastalData
ID: 36588034
There... I just worked up a new test... in my simulated development environment, where everything is all on one machine, it did work, BUT, in the production environment, tested from two different computers, it did not work...

In the production environment, the file share is on a server 2003 computer, and in my dev environment, it's all on Win 7 64 bit, but in both cases the file share location is a mapped drive, and permissions are controlled by Active Directory...

This doesn't really sound like a permissions problem to me, though, wouldn't you agree?
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 36588123
just tried placing the  .doc in a shared folder, it work, did not have a problem.

<This doesn't really sound like a permissions problem to me, though, wouldn't you agree?>

from the computer that is giving error(use the user logon), can you open the .doc manually, do some editing and save..
0
 
LVL 3

Author Comment

by:CoastalData
ID: 36588245
Oh yes, we open and edit those files all day, every day.

Oh well, I'm just going to go with "Application.Followhyperlink "Pathtodoc"", as that seems to make the problems with word into a non-issue.

Thanks for your help though, Cap!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

943 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

6 Experts available now in Live!

Get 1:1 Help Now