background: In access, I'm looping through a recordset to
populate generate Word documents (one per row)
problem: after calling doc.saveAs([filename]) and then
doc.close, my Word object becomes 'unhinged'

here's a snippet of code:
Dim objWord As Word.Application
Dim objDoc As Word.Document 'Document Object
Set objWord = CreateObject("Word.Application")

While Not rsSource.EOF
set objDoc = objWord.Documents.Add
' skipping actual formfield populating code
objDoc.saveAs strFilename
objDoc.close
rsSource.MoveNext
wend

watching the local variables, I see objWord = "Microsoft
Word" up until I call objDoc.close.

If I add objWord.Visible = True
I can even see my documents being populated and then when
closing the doc, Word app itself also quits.

I've even tried opening up a second temporary doc so that
it'll stick around but with Visible=True, I see that both
docs get closed.

Any help would be appreciated.
Thanks
Billy

Re: doc.close causing application to quit by Doug

Doug
Thu Dec 11 00:56:31 CST 2003

Hi Billy,

Apart from Dimming the equivalent of objWord and objDoc as Objects (=Late
Binding), I make frequent use of similar code without running into that
problem. So try using Late Binding rather than Early Binding.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
"Billy Chan" <bhchan@lasuperiorcourt.org> wrote in message
news:038201c3bf69$70570bd0$a401280a@phx.gbl...
> background: In access, I'm looping through a recordset to
> populate generate Word documents (one per row)
> problem: after calling doc.saveAs([filename]) and then
> doc.close, my Word object becomes 'unhinged'
>
> here's a snippet of code:
> Dim objWord As Word.Application
> Dim objDoc As Word.Document 'Document Object
> Set objWord = CreateObject("Word.Application")
>
> While Not rsSource.EOF
> set objDoc = objWord.Documents.Add
> ' skipping actual formfield populating code
> objDoc.saveAs strFilename
> objDoc.close
> rsSource.MoveNext
> wend
>
> watching the local variables, I see objWord = "Microsoft
> Word" up until I call objDoc.close.
>
> If I add objWord.Visible = True
> I can even see my documents being populated and then when
> closing the doc, Word app itself also quits.
>
> I've even tried opening up a second temporary doc so that
> it'll stick around but with Visible=True, I see that both
> docs get closed.
>
> Any help would be appreciated.
> Thanks
> Billy
>
>