I am working on an Access database that generates some emails using a merge called from VBA code in an Access database. The problem is that if I open a new Word document and start merging (VBA), Word will open the same Access database (which is already open) to receive the data. Is there any way to prevent this? So, is the database instance already open?
After some testing, I get a strange behavior: if I open an Access database containing a SHIFT key, then a merge will not open another Access instance of the same database. If I open the Access database without saving the key, I will get the described behavior.
My email merge code is:
On Error GoTo ErrorHandler Dim word As word.Application Dim Form As word.Document Set word = CreateObject("Word.Application") Set Form = word.Documents.Open("tpl.doc") With word word.Visible = True With .ActiveDocument.MailMerge .MainDocumentType = wdMailingLabels .OpenDataSource Name:= CurrentProject.FullName, ConfirmConversions:=False, _ ReadOnly:=False, LinkToSource:=False, AddToRecentFiles:=False, _ PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _ WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _ SQLStatement:="[MY QUERY]", _ SQLStatement1:="", _ SubType:=wdMergeSubTypeWord2000, OpenExclusive:=False .Destination = wdSendToNewDocument .Execute .MainDocumentType = wdNotAMergeDocument End With End With Form.Close False Set Form = Nothing Set word = Nothing Exit_Error: Exit Sub ErrorHandler: word.Quit (False) Set word = Nothing ' ... End Sub
It's all about Access / Word 2003.
Update # 1 It would also help if someone could tell me what exactly is the difference between opening access with or without a SHIFT key. And if you can write some VBA code to enable "functions", therefore, if the database is opened without a SHIFT key, it at least "mimics" it.
Cheers, Gregor
source share