
Mail merge from Access try to open an already open DB
Hi,
I need some help with my database project in VB 6 using Access & Word
2000.
What I'm trying to do is a mail merge in Word 2000 coded in VB from my
Access application. The problem is that the mail merge always tried to
open a new copy of my Access Database (that is already open) and that
cause me to see a warning message: "The database has been placed in a
state by user 'Admin' on machine 'machinename' that prevents it from
being opened or locked." I see this warning 3 times, then Word finally
do the mail merge but I now have 3 copies of access running (without
files opened). Then if I close the Word application from my VB code,
Word close and also my running Access application, leaving me only
with my 3 access windows without files opened. Can anybody help me?
here is my code:
'dclare les variables
Dim strFormLetterFile As String
Dim strDataSourceDB As String
Dim strDataSourceQuery As String
Dim strConnect As String
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim wrdMerger As Word.MailMerge
'nom du formulaire pr-publipost ouvrir
strFormLetterFile = "C:\mes documents\fr_fax_acc.dot"
strDataSourceDB = "C:\WINDOWS\Bureau\estimation ACC- word.mdb"
strDataSourceQuery = "qry_tlcopieur"
'Create a new instance of word
Set wrdApp = New Word.Application
'Open the Word document - the form letter to be sent out
Set wrdDoc = wrdApp.Documents.Add(strFormLetterFile)
'establish a MailMerge object using this formletter
Set wrdMerger = wrdDoc.MailMerge
With wrdMerger
.MainDocumentType = wdFormLetters
.OpenDataSource Name:=strDataSourceDB, _
LinkToSource:=True, AddToRecentFiles:=False, _
Connection:="QUERY " & strDataSourceQuery
.Destination = wdSendToNewDocument
.DataSource.FirstRecord = 1
.DataSource.LastRecord = 1
.Execute
End With
'ferme le 1er word contenant le formulaire fusionner
wrdDoc.Close wdDoNotSaveChanges
ActiveDocument.SaveAs "ppp.doc" 'TODO: ask filename to user
ActiveDocument.Close wdDoNotSaveChanges
wrdApp.Quit
'return focus to VB and notify when done
Me.SetFocus
MsgBox "merge process completed"
Set wrdApp = Nothing
Thanks
Pierre