Solved

Access doesn't release Word doc after opening it

Posted on 2011-09-23
12
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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
10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

 
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

623 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