dongledell
Technical User
Still having problems with a mailmerge document, but now for different reasons. If I use word to create a mailmerge with absolute addresses to the datasource (db and table) then save it, everything runs fine. As soon as I remove all links in the word doc, just add fields, then in the VBA code add an opendatasource command, it all goes to pot - loads of errors left right and centre.
This is using Acc'97 word '97 in office XP
Some of the (most relevant)code...
This is using Acc'97 word '97 in office XP
Some of the (most relevant)code...
Code:
Public Function OpenWordDocs(ByVal strWrdDocName As String, strDBmergeSource As String, _
strTblMergeSource As String)
On Error GoTo Err_OpenWordDocs
DoCmd.SetWarnings False
Dim objWord As Word.Document
Dim wrdMerge As Word.MailMerge
Set objWord = GetObject(strWrdDocName, "Word.Document")
Set wrdMerge = objWord.MailMerge
objWord.Application.Visible = False
objWord.Application.DisplayAlerts = wdAlertsNone
With wrdMerge
.OpenDataSource Name:=strDBmergeSource, LinkToSource:=True, AddToRecentFiles:=False, _
Connection:="TABLE " & strTblMergeSource
.Destination = wdSendToNewDocument
.Execute
End With
With objWord
.Application.Options.PrintBackground = False
.Application.ActiveDocument.PrintOut
.Application.quit wdDoNotSaveChanges
End With
objWord.Application.DisplayAlerts = wdAlertsAll
DoCmd.SetWarnings True
Exit_OpenwordDocs:
DoCmd.SetWarnings True
Exit Function
Err_OpenWordDocs:
MsgBox Err.Description
Resume Exit_OpenwordDocs
End Function