doc.close causing application to quit

B

Billy Chan

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
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top