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

Closing word from Access, still sticking around

Status
Not open for further replies.

ChrisCalvert

Technical User
Mar 18, 2002
231
US
I am trying to initiate a mail merge in Word 2000 from a button in an Access 2000 form, on Windows 2000. The
button calls the function below. I need the Word merge to open, print, and close as quickly as possible; and not ask to save or anything.
-----------------------------

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
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 the desktop, it immediately closes, with no questions. So, maybe I need to move the focus or something?

How should I do this?
 
objWord.Application.Quit (wdexit)
set objWord = Nothing 'kills the object instance from memory petersdaniel@hotmail.com
"If A equals success, then the formula is: A=X+Y+Z. X is work. Y is play. Z is keep your mouth shut." --Albert Einstein

 
Thanks for the response, but that did not seem to change the behavior at all. Here is what happens, it opens the master document, merges to a new document, prints, closes the merged document, hangs on the master document with 'reading record 1' at the bottom. Once again, clicking on any other thing (taskbar icon, desktop, etc) will result in the master document closing without saving or asking.
 
The following works fine for me using access 97 to call word 2000 on win 98.I call word and the word document seperately, and close seperately.

myApp = modSettings.AppPath & modSettings.AppName
Set oApp = GetObject(, Word.Application)
Set oDoc = oApp.Documents.Open(parTemplatePath)
DoEvents

With oDoc.MailMerge
conStr = "DSN=MS Access " _
& "Database;DBQ=" & myApp & ";" _
& "FIL=MS Access;"
.OpenDataSource Name:=myApp & "." & modSettings.AppType, _
ReadOnly:=True, LinkToSource:=True, _
Connection:=conStr, sqlstatement:="SELECT * FROM [" & parTable & "]"
.Destination = wdSendToPrinter
.Execute
End With
DoEvents
'oApp.Visible = True
oDoc.close wdDoNotSaveChanges

funMergeToTemplate_exit:
oApp.Quit False
Set oApp = Nothing
Exit Function
 
I am trying to complete a mail merge in Word 2000 from Access 2000. The problem is that I cannot get Word to close after the mail merge has printed. I had posted this problem before, but I was never really able to get this solved...so I thought I'd try again. Here is what happens:
1. Word opens and links.
2. Word creates the merged document, and switches to it.
3. Word prints and closes the merged document.
4. I am left viewing the original document, which reads 'Word is reading record 1' at the bottom.
This window does not close by itself. However, once I click on anything other than Word (any taskbar icon, etc.) this window closes.

Here is the (mostly borrowed)code I am using:

Public Function DoStopMerge()
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
objWord.Application.Quit (wdexit)
Set objWord = Nothing 'clears object instance from memory
End Function

I would be extremely appreciative of any help that could be provided. I just need that window to close without the extra click.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top