Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opendatasource causing problem?!

Status
Not open for further replies.

dongledell

Technical User
Dec 10, 2002
26
GB
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...

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top