Mailmerge doc will not open from Access 2003
I am using Access 2003 to open a Mail Merge document using the following VB code. The document uses a text file as the datasource. This worked in Access 2000, but the document will not open in Access 2003, word opens and the status bar displays "docname.doc: 1,222 characters..." then the document never opens. If I remove the "WordDoc.Close (False)" line the document will display, but not with the updated merge data from the datasource, instead it opens with the saved data from the "template" or original merge document. As I said this code works perfectly in earlier versions of Access.
Function MergeWord(strDocName As String)
Dim WordApp As Object ' running instance of word
Dim WordDoc As Object ' one instance of a word doc
Dim strActiveDoc As String ' doc name (no path)
Dim lngWordDest As Long ' const for dest, 0 = new doc, 1 = printer
On Error GoTo CreateWordApp
Set WordApp = GetObject(, "Word.Application")
On Error Resume Next
Set WordDoc = WordApp.Documents.Open(strDocName)
strActiveDoc = WordApp.ActiveDocument.Name
With WordDoc.MailMerge
.Destination = 0 ' 0 = new doc
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = 1
.LastRecord = 1
End With
.Execute Pause:=True
End With
WordDoc.Close (False)
WordApp.Visible = True
WordApp.Windows(WordApp.Windows.Count).Activate
AppActivate "Microsoft Word"
WordApp.WindowState = 0 'wdWindowStateRestore
Set WordApp = Nothing
Set WordDoc = Nothing
DoEvents
Exit Function
CreateWordApp:
...
End Function
Any help would be appreciated.
Thanks
ucmlamb
|