Solved

Access doesn't release Word doc after opening it

Posted on 2011-09-23
12
239 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
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 119

Expert Comment

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

Author Comment

by:CoastalData
Comment Utility
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
Comment Utility
Yes
0
 
LVL 3

Author Comment

by:CoastalData
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
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 …
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

771 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

11 Experts available now in Live!

Get 1:1 Help Now