Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Yet another question on object life

Status
Not open for further replies.

Scoty

Programmer
Oct 25, 2000
278
US
Hi All,
I'm still working on that dynamic faxing database. Here is the problem I am having today. I have 2 mail merges controlled by the same database. I reference the object in my declaration by using
Code:
Dim objHMOWord As Word.Document
Then I call the objects from my cmdButton Code like
Code:
Set objHMOWord = GetObject ("G:\hcm\common\scott\faxdocs\hmo.doc", "Word.Document")
HMOMergeIt lsName, lrsHMO.Fields(0), "hmoMemb"
Then it runs the function which I have coded as so
Code:
Function HMOMergeIt(lsName As String, lsAutoCounter As Single, lsTableName As String)
   Dim lsSQLStatement As String
   Dim lsFieldName As String
   lsFieldName = "hmomemb.autocounter"
               ' Create the SQLStatement
            lsSQLStatement = "SELECT " & lsTableName & ".*," & lsFieldName & Chr(13) & "FROM " & lsTableName & " " & Chr(13) & "WHERE (((" & lsFieldName & ")=" & lsAutoCounter & "));"
            objHMOWord.MailMerge.OpenDataSource _
                Name:="g:\hcm\common\priv1\ptc\Nextry.mdb", _
                SQLStatement:=lsSQLStatement
            ' Execute the mail merge.
            objHMOWord.MailMerge.Execute
            ' Save the merged document
            objHMOWord.Application.ActiveDocument.SaveAs filename:="G:\hcm\common\scott\faxdocs\" & lsName
            ' Closing the new doc
            objHMOWord.Application.ActiveDocument.Close False
End Function

The problem comes into play when I get back to the code of the cmdButton. I use:
Code:
Set objHMOWord = Nothing
I need word to "go away" so I can start my next merge. It stays there in the back ground. If I dont hover over my computer with task manager showing and kill off the word application (which is by the way hidden). It messes up the next merge letter. Am I using the wrong kill command. Why won't word unload on the
Code:
objHMOWord = Nothing
command?

Please help
Scotty ::) Become better informed. Lean from others' mistakes. You could not live long enough to make them all yourself."
-- Hyman George Rickover (1900-86),
 
You are just clearing the reference you are not actually closing the object. To do this put

objHMOWord.Quit False

right before the line:

Set objHMOWord = Nothing

This should do what you want.
Shane
 
Shane,
Thanks for your response. Unfortunately, I had already tried that. When I do I get and error stating:
Run-time error '438'.
Object doesn't support this property or method

When I type it in quit is not a choice or methods or properties. Any other Idea's?
Thanks
Scotty ::) Become better informed. Lean from others' mistakes. You could not live long enough to make them all yourself."
-- Hyman George Rickover (1900-86),
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top