Word merging

A

Amirallia

Hi,

Here is my code to merge a word document directly from a access
application. All is ok, it's work !

Sub MergeIt(bPrintDirectly As Boolean)
Dim objWord As New Word.Document
Dim mySQL As String

'***********
On Error GoTo Err_MergeIt
Set objWord = GetObject("toto.dot", "Word.Document")

objWord.Application.Visible = Not bPrintDirectly

objWord.MailMerge.MainDocumentType = wdFormLetters

mySQL = "SELECT Doss.* FROM Doss WHERE (Doss.Sel=-1)"

objWord.MailMerge.OpenDataSource _
Name:=glbPathDB, _
ConfirmConversions:=False, _
LinkToSource:=True, _
AddToRecentFiles:=False, _
Connection:="DSN=MS Access Database;DBQ=" &
glbPathDB & ";DriverId=25;FIL=MS
Access;MaxBufferSize=2048;PageTimeout=5;", _
SqlStatement:=mySQL

objWord.MailMerge.Destination = wdSendToNewDocument

objWord.MailMerge.Execute

If bPrintDirectly Then
objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut
End If

Exit_MergeIt:
objWord.Close
Set objWord = Nothing
Exit Sub

Err_MergeIt:
MsgBox "MergeIt:" & Err.Number & " " & Err.Description
Resume Exit_MergeIt
End Sub

But when Word is opened before merging, and I execute the merging, the
word document is ok, but Word ask me if I want save the toto.dot model
because it was modified ????

Any idea ???

Thanks in advance !
 

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