
Mail Merge - Word was unable to open the datasource
I have written an application using Access 2000. It
includes a mail merge facility which I have implemented
using late binding. I have used late binding because I
have no control of what is implemented on a user's machine
and would like the program to function with Word 97, Word
2000 and Word XP.
The mail merge feature works in a run time environment
with Word 2000 and Word XP but the same program errors on
a Win 98 machine with Word 97 installed. The error I am
receiving is:
Err Number = 5922
Word is unable to open the datasource
I tried connecting to the datasource directly from Word
and received the following error:
This program is not set to run in MS-DOS mode and
cannot run while ohter programs are running. All
other programs will close if you choose to continue.
Choosing the continuation options does not do anything.
I don't know whether the above error has any bearing on
the message I am receiving from my application (Error
5922).
This is a copy of the code:
' Get/Create an instance of Microsoft Word.
bnIsRunning = True
bnCreateWord = False
Set WordApp = GetObject(, "Word.Application")
If bnCreateWord = True Then
Set WordApp = CreateObject("Word.Application")
End If
' Create a new, empty document.
Set WordDoc = WordApp.Documents.Add
With WordDoc.mailmerge
If UseDDE Then
strConnect = "tblCustomer"
Else
' Path to database.
strConnect = "DSN=MS Access " _
& "Database;DBQ=" & CurrentDb.Name _
& ";" _
& "FIL=MS Access;"
End If
' Path to database.
.OpenDataSource _
Name:=CurrentDb.Name, _
ReadOnly:=True, LinkToSource:=True, _
Connection:=strConnect, _
SQLStatement:="SELECT * FROM [tblMailMerge]"
End With
With WordDoc.mailmerge
' Merge the data to a new document.
'.Destination = wdSendToNewDocument
.Destination = 0 ' 0 (zero) = new document
' Execute the mail merge.
'.Execute
' If user specified to print the document, disable
' background printing, and then print the merged
document.
If PrintDoc Then
.Application.Options.PrintBackground = False
.Application.ActiveDocument.PrintOut
End If
End With
' Show the instance of Microsoft Word.
WordApp.Visible = True
CreateMergeDocError:
Select Case Err.Number
Case 429
If bnCreateWord = False Then ' Word is not
running, attempt to create object
bnIsRunning = False
bnCreateWord = True
Resume Next
Else
intReturn = MsgBox("Mail Merge: Error " &
Str(Err.Number) & " " & Err.Description, vbInformation,
glAppname)
End If
Case Is <> 0
intReturn = MsgBox("Mail Merge: Error " & Str
(Err.Number) & " " & Err.Description, vbInformation,
glAppname)
End Select
Any help will be most appreciated.
CR