PRB: Prompted To Select a Data Source While Automating Word 2002 Mail Merge

Article translations Article translations
Article ID: 279462 - View products that this article applies to.
This article was previously published under Q279462
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all


When you call the OpenDataSource method while automating Word 2002, the Select Data Source dialog box appears. If Word is not visible, it may appear to have stopped responding.


When you call OpenDataSource, the Select Data Source dialog box typically appears if you have not provided enough information to connect to the data source. By default, Word 2002 attempts to connect to the data source by using the Office DataSource Object (ODSO). ODSO requires the complete path and file name to either a database or an Office DataSource Connection (.odc) file for the Name argument. If you provide the Name argument with an empty string, the Select Data Source dialog box appears.


To avoid the dialog box to select a data source, do one of the following:
  • Supply the Name argument of OpenDataSource with the full path to a file-based database, such as a Microsoft Access database, a Microsoft Excel workbook, or a text file.
  • Supply the Name argument of OpenDataSource with the full path to an .odc file.
  • Supply the SubType argument of OpenDataSource with wdMergeSubTypeWord2000 to emulate Word 2000 behavior.
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

More information

With Word 97 and Word 2000, the following Automation code creates and executes a mail merge against SQL Server data without user intervention.

Note You must change UID <username> and pwd =<strong password> to the correct values before you run this code. Make sure that UID has the appropriate permissions to perform this operation on the database.
Dim oApp As Word.Application
Dim oDoc As Word.Document

'Start a new document in Word.
Set oApp = New Word.Application
'Make Word visible (to see the dialog box).
oApp.Visible = True

Set oDoc = oApp.Documents.Add
With oDoc.MailMerge
  .MainDocumentType = wdFormLetters

  'Set up the data source for the mail merge.
  Dim sSQL As String
  Dim sConn As String
  sSQL = "Select au_id, au_lname, au_fname from pubs.dbo.authors"
  sConn = "DSN=YourSQLServer;DATABASE=pubs;uid=<username>;pwd=<strong password>;"
  .OpenDataSource Name:="", Connection:=sConn, SQLStatement:=sSQL

  'Set up the document with the fields.
  .Fields.Add Range:=oApp.Selection.Range, Name:="au_id"
  .Fields.Add Range:=oApp.Selection.Range, Name:="au_lname"
  .Fields.Add Range:=oApp.Selection.Range, Name:="au_fname"

  'Execute the merge.
  .Destination = wdSendToNewDocument
End With

'Clean up.
Set oDoc = Nothing
Set oApp = Nothing
With Word 2002, however, the Select Data Source dialog box appears when the OpenDataSource method is called because the Name argument is an empty string. To correct this problem so that the mail merge can execute without user intervention, change the following line in the sample code
  .OpenDataSource Name:="", Connection:=sConn, SQLStatement:=sSQL
  .OpenDataSource Name:="", Connection:=sConn, SQLStatement:=sSQL, _
                  SubType:= wdMergeSubTypeWord2000


For more information, see the following article in the Microsoft Knowledge Base:
289830 PRB: Prompt to Select Table with Word 2002 Mail Merge Code for Excel or Access Data Source


Article ID: 279462 - Last Review: October 26, 2013 - Revision: 3.0
Applies to
  • Microsoft Word 2002
kbnosurvey kbarchive kbautomation kbprb KB279462

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from