logo
search
Others

How to Connect Access Database to Word via VSTO and VB.NET

Maira MehtabMaira Mehtab Oct 1, 2026 869 views

Question details

The user wants to retrieve data from an Access database, display it in Word controls, and generate or print documents using a VSTO Word solution in VB.NET.

Connecting an Access Database to a Word VSTO Solution using VB.NET
Product
Microsoft Word
Device & OS
not provided
Scenario
Developing a VSTO Word add-in or document-level solution that needs to dynamically load data from an Access database into document controls.
Observed behavior
Standard mail merge displays unwanted query dialog prompts, leading the user to seek a programmatic VB.NET solution using design-time and runtime data binding.
Before you start

Ensure you have Visual Studio installed with the 'Office/SharePoint development' workload, and verify that your target Access database (.accdb or .mdb) is accessible and not exclusively locked.

Solution 1Recommended

Programmatic Data Binding via VSTO and VB.NET

Use a typed DataSet, TableAdapter, and BindingSource to securely retrieve and display data without triggering mail merge prompts.

By utilizing VB.NET data components at both design time and runtime, you can fully automate how Word interacts with an Access database. This approach bypasses the limitations of the native mail merge feature, such as unexpected SQL query prompts.

1
Create a Data Source

In Visual Studio, open the Data Sources window and add a new Data Source. Select 'Database', then 'Dataset', and establish a connection to your Access database.

2
Generate DataSet and TableAdapter

Configure the connection to generate a typed DataSet and a TableAdapter in your VB.NET project, which will handle the underlying SQL queries and data structure.

3
Bind Data to Word Controls

Drag tables or fields from the Data Sources window directly onto your VSTO document or Action Pane. This automatically creates a BindingSource linking your controls to the dataset.

4
Retrieve Data at Runtime

In your VB.NET code (e.g., the Document_Startup event), call the TableAdapter's 'Fill' or 'GetData' method to populate the dataset with the latest records from Access before printing or displaying the document.

Programmatic Data Binding via VSTO and VB.NET
Runtime Refresh: Always ensure you call the Fill method whenever you need to reflect the most current database updates in your Word document.
Free Microsoft Office alternative

Looking for a Lightweight Office Suite? Try WPS Office

Developing complex VSTO solutions can be highly resource-intensive. If you are looking for a fast, highly compatible, and free alternative to Microsoft Office for your daily document processing and built-in mail merge tasks, WPS Office provides excellent performance without the heavy overhead.

  1. 1. Download the Installer: Visit the official WPS Office website and download the free installation package.
  2. 2. Install WPS Office: Run the installer and follow the quick on-screen instructions to set up the software.
  3. 3. Open Your Documents: Launch WPS Writer and open your existing .docx files directly, maintaining full layout and formatting compatibility.
Fully compatible with Microsoft Word (.docx) and Excel (.xlsx) formatsIntuitive built-in mail merge tools that require no programming knowledgeLightweight installation that consumes minimal system resourcesFree to download and use for everyday document creation and editing
microsoft office alternative - wps office

Frequently Asked Questions

Why does Word mail merge display a query prompt when connecting to Access?

This happens due to Office security settings checking OLE DB or DDE connections before executing SQL commands. Using programmatic data access via VSTO or VBA bypasses these interactive user prompts entirely.

What is the difference between a DataSet and a TableAdapter in VB.NET?

A DataSet is an in-memory cache of data retrieved from the database, while a TableAdapter provides the communication link, executing SQL queries or stored procedures to fetch the data into the DataSet and send updates back to Access.

Do end-users need Microsoft Access installed to run my VSTO Word solution?

Users do not need the full Microsoft Access application installed to run the solution. However, they must have the correct Microsoft Access Database Engine (ACE OLEDB provider) installed on their machine to allow the VSTO add-in to read .accdb or .mdb files.