Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Access doesn't release Word doc after opening it

Posted on 2011-09-23
12
Medium Priority
?
251 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 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

926 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