WINWORD.EXE is not closing -- file lock not being released

The following code runs when we send out what is called "Closing Instructions" fax.

For some reason the WINWORD.EXE is not being closed (I go into Task Manager and it is still there)

Also, the file is not being closed on the Server.

The Word file in question is a template file (.DOT).

Looking at the code below, is there any reason why WINWORD.EXE would be left open or the file lock not released, or the file not closed, etc.?

We use Office automation heavily in our Access application.  I really need an answer to this!


~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Sub sbGenerateClosingInstructions(strDocType As String)
    'The fax that has names and titles in it.
    Dim strFaxRaw As String
   
    Dim strTempUniqueCode As String
   
    Dim strCover As String
   
    Dim strUpdatedGrantApp As String

    Dim strToField As String
    Dim strSubject As String
    Dim strFile1 As String, strFile2 As String
    Dim fPrintOut As Boolean
    Dim strTempInText As String
    Dim strTempFieldName As String
    Dim FBoldSetting As Boolean
    Dim FItalicSetting As Boolean
    Dim FUnderlineSetting As Boolean
    Dim intFontSize As Long
    Dim intBookmarkCount As Long
   
    Dim strFaxOutTable As String
    'Const strFaxOutTable As String = "qryPrintQuery"
   
    Dim strCertifiedFaxDocumentToSend As String
    Dim strCertifiedFaxCovertToSend As String
    Dim strCIFaxPath As String
    Dim strCI As String
    Dim lngEntryID As Variant
    Dim intCounter As Long
       
    Set recTemp = New Recordset
   
    Dim strLetterName As String
    Dim intRecordCount As Long
    Dim dblOrigRandomID As Double
    Dim dblNewRandomID As Double
    Dim varRandomID As Variant
   
    Dim strFaxType As String
    Dim fGoes
    Dim strOutFile As String, strOutPath As String, strOutFile2 As String
    Dim TimeIn As Date
    Dim bk As Bookmark
   
    intCounter = 0
   
    TimeIn = Now
       
    recTemp.CursorLocation = adUseClient
       
    strFaxOutTable = "SELECT tblEntries.EntryID, tblEntries.Buyer, " & _
    "tblEntries.BuyerFirstName, tblEntries.BuyerLastName, tblEntries.EscrowNumber, tblEntries.CurAddr, " & _
    "tblEntries.City, tblEntries.State, tblEntries.Zip, FormatMoney([Grant]) AS GrantAmount, " & _
    "FormatMoney([SSF]) AS SSFAmount, [Lender] & ""'s"" AS MC, tblEntries.TentativeClosingDate AS TCD, " & _
    "tblEntries.TitleAgency, tblEntries.[Closing Agent] AS CA, tblEntries.TitleFax, tblEntries.LO, tblEntries.Lender, " & _
    "tblEntries.LenderFax, [SellerAddress] & IIf(nz([SellerAddress],"""")="""","""","", "") & [SellerCity] & IIf(nz([SellerCity],"""")="""","""","", "") & [SellerState] & "" "" & [SellerZip] AS PropertyAddress FROM tblEntries WHERE (((tblEntries.EntryID)= " & [EntryID] & "));"
       
    'Open tblFaxOutHolder
    recTemp.Open strFaxOutTable, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
   
    'Count of records (faxes to send)
    intRecordCount = recTemp.RecordCount
   
    If intRecordCount > 0 Then
   
        'LOOP through all records in tblFaxOutHolder
        Dim objWord1 As New Word.Application
   
        Do While recTemp.EOF = False
               
            strCertifiedClosingInstructionsToSend = "P:\Documents\fmci2page.dot"
                   
            objWord1.Documents.Add strCertifiedClosingInstructionsToSend
                   
            'LOOP THROUGH CLOSING INSTRUCTIONS BOOKMARKS
            For Each bk In objWord1.ActiveDocument.Bookmarks
                ' if the name is the same as a bookmark name, increment counter + 1
                strTempInText = bk.Name
           
                ParseBookmark strTempInText, strTempFieldName, FBoldSetting, FItalicSetting, FUnderlineSetting, intFontSize, intBookmarkCount
           
                bk.Select
                Select Case Nz(recTemp.Fields(strTempFieldName).Value, "")
                    Case ""
                        'objWord1.Selection.Delete
                        objWord1.Selection.EndKey
                       
                       
                    Case Else
                        objWord1.Selection.Font.Bold = FBoldSetting
                        objWord1.Selection.Font.Italic = FItalicSetting
                        objWord1.Selection.Font.Underline = FUnderlineSetting
                        objWord1.Selection.Font.Size = intFontSize
                        If strTempFieldName = "TitleFax" Then
                            objWord1.Selection.TypeText ConvertRawPhone(recTemp.Fields(strTempFieldName).Value)
                        Else
                            objWord1.Selection.TypeText recTemp.Fields(strTempFieldName).Value
                        End If
                End Select
            Next
       
            strTempUniqueCode = UniqueCode
       
            strCIFaxPath = "K:\coverpge\adv\fmci2page" & "-" & strTempUniqueCode & ".doc"
       
            objWord1.ActiveDocument.SaveAs strCIFaxPath
           
            If strDocType = "Print" Then
                objWord1.ActiveDocument.PrintOut
            End If
           
            If strDocType <> "Create" Then
                objWord1.ActiveDocument.Close
            End If
           
            If strDocType = "Create" Then
                objWord1.Application.Visible = True
            End If
           
       
            strFaxRaw = Nz(recTemp("TitleFax"), "")
       
            'strFaxRaw = "8012260878"
       
            strToField = "OC-" & Nz(recTemp("EntryID"), "") & "-" & Nz(recTemp("CA"), "") & "-" & Nz(recTemp("TitleAgency"), "")
            strSubject = recTemp("EntryID") & "-OC-" & recTemp("Buyer")
       
            strCI = "adv\fmci2page" & "-" & strTempUniqueCode & ".doc"
           
            If strFaxRaw = "" And strDocType = "Fax" Then
                MsgBox "This must have a fax number for the title agency before you can send out a fax."
                Exit Sub
            End If
                   
            If strDocType = "Fax" Then
                fGoes = GenFMText(strTempUniqueCode & ".txt", "J:\HighPriority\", strFaxRaw, strCI, strToField, , , , , , strSubject)
            End If
           
            DoEvents
       
            intCounter = intCounter + 1
            recTemp.MoveNext
        Loop
       
        If strDocType = "Fax" Then
            DoEvents
            ConfirmOff
            DoCmd.RunSQL "UPDATE tblEntries SET CIFaxYN = True, CIFaxDate = #" & Now() & " #, CIFaxConfYN = False, CIFaxConfDate = Null WHERE EntryID=" & Me.EntryID & ";"
            'DoCmd.RunSQL "INSERT INTO tblComments ( CommentType, Comment, EntryID ) SELECT ""CIFax"", ""Closing Instructions Faxed"", EntryID FROM tblEntries WHERE EntryID=" & Me.EntryID & ";"
            ConfirmOn
            fnAppendComment Me.EntryID, "CIFax", "Closing Instructions Faxed"
           End If
           
        DoCmd.Save acForm, "frmPrintWordDocs"
               
        Me.Refresh
    End If
   
    If strDocType = "Print" Then
        MsgBox "Closing Instructions Printed"
    End If
   
    If strDocType = "Create" Then
        MsgBox "Closing Instructions Created"
    End If
   
    If strDocType = "Fax" Then
        MsgBox "Closing Instructions Faxed"
    End If
   
   
    If strDocType <> "Create" Then
        objWord1.Quit
        Set objWord1 = Nothing
        Set recTemp = Nothing
    End If
           
End Sub
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

criCommented:
Difficult to debug w/o having the whole environment.

a) Which Word version and service release do you run ?

b) Operating system version/service release for server/client ?

c) Did you try your code on a non-networked PC ?


BTW: Perhaps of use http://www.helenfeddema.com/CodeSamples.htm

0
Tom KnowltonWeb developerAuthor Commented:
a)  Word Version:  Word 2000 (no service release is installed)

b)  OS Version:  2000 Professional, Service Pack 3

c)  No, I have not tried the app on a non-networked PC.



0
zombieoooCommented:
Do you have Outlook open with MSWord as your e-mail editor?  This will cause the situation described as well.  Check in Outlook under Tools, Options, Mail Format Tab, and uncheck Use Microsoft Word as ...

Joel
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tom KnowltonWeb developerAuthor Commented:
I checked...a few people had MS Word as the default editor.

I have since unchecked the box for that.

I'll wait a while and see what happens.
0
PhetuCommented:
Hi,

I would use this:

dim objWord1 as object
Set objWord1 = CreateObject("word.application")

instead of your
Dim objWord1 as New word.application

And at the end of your code you should do:

Set objWord1 = Nothing

Hope it will help

Phetu
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tom KnowltonWeb developerAuthor Commented:
Phetu:

Does your way help prevent memory leaks, etc. or is it just another way of doing the same thing?

Thanks,

Tom
0
PhetuCommented:
Hi,

It prevent Word (even Excel) to stay in memory when you close the application. I've ran into a similar problem than yours and this solution solve my problem.

Phetu
0
Tom KnowltonWeb developerAuthor Commented:
Phetu:

Excellent!  Let me try this out, then.

I'll let you know.

Tom
0
Tom KnowltonWeb developerAuthor Commented:
What is the difference between:

dim objWord1 as object
Set objWord1 = CreateObject("word.application")


and


Dim objWord1 as New word.application

???
0
PhetuCommented:
It's the same thing except that one is working correct!

Phetu
0
Tom KnowltonWeb developerAuthor Commented:
LOL...  *okay*
0
PhetuCommented:
Ok...ok.

To give you a good answer is that the both ways should work perfectly but because that "Dim objWord1 as New word.application" is not working properly the workaround is to try the instruction that i gave you!

Does it make more sense now!

Phetu :))
0
Tom KnowltonWeb developerAuthor Commented:
Yes.

Incidentally, I tried out the "OLD" code (the way I was doing it) and faxed several letters.  The WINWORD.EXE process cleaned-up just fine every single time!

It seems to be in a network environment where one .DOT file is being used by multiple people.

Tom
0
PhetuCommented:
I'm not sure that your problem is caused by the .DOT file because it's a common problem that people had with Excel and Word.

You'll see.

Pehtu
0
Tom KnowltonWeb developerAuthor Commented:
You sound pretty sure about this.
0
Tom KnowltonWeb developerAuthor Commented:
0
PhetuCommented:
They are talking about the visible property of the Word application. It's because when you start a Word instance in VBA you do not have to make it visible to the user. And if another instance is started "manually" by the user, the wrong instance is activated (the VBA one). So if the user close this instance, your vba program won't find the instance that it creates.

But your problem is not this at all!!! It remain in memory. They are not talking about that!

Phetu
0
Tom KnowltonWeb developerAuthor Commented:
Okay.
0
Tom KnowltonWeb developerAuthor Commented:
Thanks,

Tom
0
PhetuCommented:
Just to make you feel more relax, take a look at this.

Phetu
0
Tom KnowltonWeb developerAuthor Commented:
???
0
Tom KnowltonWeb developerAuthor Commented:
Got it.

Glad to see this worked for somebody else!

I stil haven't had time to try this out yet.

Tom
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.