How to Pass Access Text Fields to Word with VBA or Mail Merge
Question details
The user needs to insert database records from Microsoft Access into an editable Word document for document generation.

- Product
- Microsoft Access and Microsoft Word
- Device & OS
- not provided
- Scenario
- Automating the creation of documents by transferring text fields from an Access database to a Word template.
- Observed behavior
- Users seek the correct methods to push data to Word but often encounter missing library references, incorrect template paths, or connection errors when running VBA scripts.
Ensure that your target Word template (.dotx or .docx) is saved in an accessible local directory, and note down the exact file path before beginning the setup.
Use Access Mail Merge for Standard Document Generation
The built-in Mail Merge feature is the easiest and most reliable method for generating standard documents without writing code.
This method utilizes the native connection between Microsoft Access and Word, allowing you to quickly merge database queries into pre-formatted text documents.
Open your Microsoft Access database. In the Navigation Pane, click to select the table or query that contains the text fields you want to pass to Word.
Navigate to the 'External Data' tab on the Access ribbon. In the 'Export' group, click on the 'Word Merge' button.
In the Microsoft Word Mail Merge Wizard dialog box, choose whether to link your data to an existing Word document or create a new one, then click OK.
Microsoft Word will open. Use the 'Mailings' tab in Word to click 'Insert Merge Field' and place your Access text fields into the document layout.

Use a VBA Script for Custom Document Output
VBA provides absolute control for advanced users needing to automate specific document creation workflows directly from Access.
Fix Missing Library References in VBA
Resolve 'User-defined type not defined' or connection errors by enabling the correct library references in your VBA environment.
Try WPS Office for Seamless Document Management
While Microsoft Access and Word VBA are highly specialized setups, WPS Office provides a free, lightweight, and highly compatible alternative for everyday document generation, mail merges, and data management. Enjoy a familiar interface that handles complex documents and spreadsheets effortlessly without expensive subscriptions.

Frequently Asked Questions
Why does my VBA code fail to create the Word document?
This typically occurs if the file path provided for the Word template is incorrect or if the Microsoft ActiveX Data Objects Library reference is not enabled in the VBA Editor's Tools > References menu.
Can I format the text fields when passing them from Access to Word?
Yes. When using Mail Merge, you can apply formatting directly to the merge fields within the Word template. If using VBA, you can format the text by manipulating the properties of the Word Range object (e.g., objDoc.Range.Font.Bold = True) after inserting the text.
How do I loop through multiple records in VBA effectively?
You can loop through multiple records by using a 'While Not rs.EOF' structure in your VBA script. Ensure you include 'rs.MoveNext' before the 'Wend' or 'Loop' statement; otherwise, your script will get stuck on the first record in an infinite loop.




