ChrisCalvert
Technical User
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"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
' 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?
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?