Prompt to Select Table with Word 2002 Mail Merge Code for Excel or Access Data Source (289830)
The information in this article applies to:
This article was previously published under Q289830 SYMPTOMS
When you call the OpenDataSource method to connect a mail merge document to a Microsoft Excel or Microsoft Access data source with Word 2002, the Select Table dialog box appears. The same code, when used with Word 97 or Word 2000, runs without displaying a dialog box.
CAUSE
In Word 97 and Word 2000, if you use the path/file name for an Excel workbook or an Access database for the Name argument in the OpenDataSource method, Word uses Dynamic Data Exchange (DDE) to access the data for your mail merge, as follows:
'Retrieves data from a table in an Access database.
Dim oMM as Word.MailMerge
Set oMM = ActiveDocument.MailMerge
oMM.MainDocumentType = wdFormLetters
oMM.OpenDataSource Name:= "c:\db1.mdb", Connection:= "TABLE Customers"
'Retrieves data from a named range in an Excel workbook.
Dim oMM as Word.MailMerge
Set oMM = ActiveDocument.MailMerge
oMM.MainDocumentType = wdFormLetters
oMM.OpenDataSource Name:= "c:\book1.xls", Connection:= "MyNamedRange"
When this code is used with Word 2002, Word automatically uses the Office DataSource Object (ODSO) to access the data with OLEDB and not DDE. ODSO expects an SQL query for the data source in the SQLStatement argument of OpenDataSource and ignores the Connection argument. Because the SQLStatement argument is omitted in the code above, ODSO displays the Select Table dialog box.
RESOLUTION
To avoid the prompt, you can do the following:
- Supply the SQLStatement argument of the OpenDataSource method with a valid SQL query. Word 2002 uses OLEDB (through ODSO) for the data access, whereas Word 97 and Word 2000 continue to use DDE.
-or-
- Force Word 2002 to use DDE instead of OLEDB for the data access by supplying the SubType argument of the OpenDataSource method with wdMergeSubTypeWord2000. Note that the SubType argument is new to Word 2002; Word 97 and Word 2000 do not support this argument.
For additional information on the different data access methods you can use for a Word 2002 mail merge, click the article number below
to view the article in the Microsoft Knowledge Base:
285332 HOWTO: Automate Word 2002 with Visual Basic to Create a Mail Merge
REFERENCES279462 PRB: Prompt To Select a Data Source Appears While Automating Word 2002 Mail Merge
Modification Type: | Major | Last Reviewed: | 8/28/2003 |
---|
Keywords: | kbAutomation kbprb KB289830 kbAudDeveloper |
---|
|