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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word/Access Mail Merge..cleanup 1

Status
Not open for further replies.

ChrisCalvert

Technical User
Mar 18, 2002
231
US
I use the code below which I coppied from ..Technet, I think.
However, this opens a second copy of my database, and leaves the Merge document, and the new merged document open.
I would like to keep the second copy of my database from opening, and close the word documents, without saving anything.
I tried using 'objWord.Application.Quit' but that still asks for saving changes, so I am not sure if that is what I want.
Can anyone help me? Thanks in advance....
------------------------
Public Function MergeIt()
Dim objWord As Word.Document
Set objWord = GetObject("C:\FufilDataMerge\StopPayLetter.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source
objWord.mailmerge.OpenDataSource _
Name:="C:\FufilDataMerge\Fulfilment.mdb", _
LinkToSource:=True, _
Connection:="TABLE StopLettersData", _
SQLStatement:="SELECT * FROM [StopLettersData]"

objWord.mailmerge.Destination = wdSendToNewDocument
objWord.mailmerge.Execute

'The following line must follow the Execute statement because the
'PrintBackground property is available only when a document window is
'active. Without this line of code, the function will end before Word
'can print the merged document.

objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut

End Function
 
I know you can pass a parameter to the Quit method.

objWord.Quit False


Hope that helps....
 
Thanks. That is a step in the right direction. I am now ending with this:

objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut
objWord.Application.Quit (wdexit)

Using the (wdexit) closed the merged document but it behaves strangely with the master document. It is there with a 'hourglass' cursor, says 'reading record one' at the bottom.
Now, when I click onto any other window, or desktop, it immediately closes, with no questions. So, maybe I need to move the focus or something? How should I do this?
 
Instead of sending object.quit.false....try this

objWord.close false

I did not have any trouble with this statement...

Pat
-Once a muppet always a muppet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top