Clean up programmatically

  • Thread starter Thread starter Joanne
  • Start date Start date
J

Joanne

I have this routine that opens several docs in msword.
The user then views and/or prints the docs one at a time, then closes
each of them. When the viewer closes the last doc, I would like to
close msword and clean up programmatically.

This is the code I am using:
If Not oRst Is Nothing Then
Do While Not oRst.EOF
sfilename = "" & oRst("DocNamePath")
If Len(Dir$(sfilename)) > 0 Then
oWordapp.Visible = True
Set oDocName = oWordapp.Documents.Open(sfilename)
End If
oRst.MoveNext
Loop
End If

oRst.Close
oWordapp.Quit
Set oWordapp = Nothing
Set oDocName = Nothing
Set oRst = Nothing

Problem is it goes thru everything nicely, but closes and cleans up
before the viewer has had a chance to do any work.
I don't know how to program it so that it knows when the last file has
been closed so that it can do its job at that point instead of
immediately.
I tried putting the last 5 lines in an if/end if loop, setting it to
If Len(Dir$(sfilename)) = 0 Then
but that didn't work, so I tried setting the line to read when
If oRst Is Nothing Then
but that also didn't work.

Could you please give me a hand with this, or show me where to read up
on it and help myself?
Thanks
Joanne
 
Joanne,
My experience with OLE automation is that your procedure
will plow through all of the code until it's done, and
that includes shutting down Word. Once your users close
the last Word document, they'll be looking at the Access
form that launched Word, no? Then you could guide them as
to what to do next.
Good luck.
Geof.
 
Geof
Thanks for your input to my problem. Actually, when the user closes
the last file, word is just hanging there staring at them, and they
need to close it to go back to the Access form that launched word.
That is why I was wondering if I could close word after the last doc
is closed. Thing is, I think I might be able to do it from a word
macro, but I don't know how to call a word macro using automation in
my access form's code module.
So there lies the rub!!
Thanks for your time and consideration of this question
It is very appreciated
Joanne
 
Back
Top