?
Solved

Access doesn't release Word doc after opening it

Posted on 2011-09-23
12
Medium Priority
?
248 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 2000 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
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 start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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…

719 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