

By default, Form1 is created.Ĭlick Microsoft Word 2000 Object Library in the list of references, and then click OK. Start a new Standard EXE project in Visual Basic. On the Help menu, click Sample Databases, and then choose Northwind Sample Database to install this feature. If Northwind is not installed, start Microsoft Access 2002 or Microsoft Office Access 2003.

The data source that is used is the sample Access database Northwind.mdb. The following sample code creates and executes a mail merge for form letters by using OLEDB (by way of ODSO). To specify DDE as the data access method with OpenDataSource, supply the path and the file name to the database or the workbook for the Name argument, and wdMergeSubTypeWord2000 for the SubType argument. You can use DDE to access data in Microsoft Access databases or Microsoft Excel workbooks. SQLStatement:= "Select au_id, au_lname, au_fname from authors", _ To specify ODBC as the data access method with OpenDataSource, supply an empty string for the Name argument, an ODBC connection string for the Connection argument, and wdMergeSubTypeWord2000 for the SubType argument.Ĭonnection:= "DSN=MySQLServerDSN DATABASE=pubs uid=sa pwd= ", _ You can use ODBC for your mail merge to access data for which a user data source name (DSN) has been set up on the system. ODSO ignores any information in the Connection argument. ODSO requires that the Name argument for OpenDataSource be either a complete path to a database or a complete path to a valid ODC file. ODSO is the only mechanism by which Word can access data by using OLEDB for a mail merge. Word and other Office XP applications use the Office DataSource Object (ODSO) for OLEDB access to external data sources. OpenDataSource Name:="C:\MyDataSource.odc", _ If you provide a database for the Name argument, Word will automatically use OLEDB if there is an OLEDB provider installed that supports the database format.Įxample. To specify OLEDB as the data access method with OpenDataSource, supply the Name argument with the path and the file name to either the database or an Office DataSource Connection (.odc). OLEDB is the recommended data access method. Different combinations of these three arguments represent different data access methods for the mail merge. Of primary interest for connecting to an external data source are the Name, Connection, and SubType arguments. For a complete description of each argument, refer to the Microsoft Word Visual Basic online Help.
