Click here to Skip to main content
13,590,119 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


16 bookmarked
Posted 4 Nov 2009
Licenced CPOL

A Simple Example of Merge Document (Microsoft Access 2003)

, 5 Nov 2009
Rate this:
Please Sign up or sign in to vote.
A simple example of merge document (Microsoft Access 2003)


This article will describe how easily you can merge a document from Microsoft Access 2003 database.


It is a very common practice to create various word documents from the database and merge the document. Most VBA developers are familiar with that. In this article, I would like to demonstrate how you can fetch a record form the database tables by executing transact SQL statement and merge all the records in a document.

Using the Code

This is a very effortless way. You just need some basic idea on MailMerge.OpenDataSource method.

  • MailMerge.OpenDataSource: Attaches a data source to the specified document, which becomes a main document if it's not one already.

Sample Example

Public Sub MergeDocument(strDocumentPath As String _
                      , strDocumentFile As String _
                      , strSQLStatement As String)
On Error GoTo ErrorHandler

Dim ObjApplication As Word.Application
Dim ObjDocument As Word.Document


Dim strSourceName As String
Dim MergeSubType As WdMergeSubType

    strSourceName = "C:\MyDatabase.mdb"
    MergeSubType = wdMergeSubTypeWord2000
    Set ObjDocument = GetObject(strDocumentPath & strDocumentFile, "Word.Document")
    ObjDocument.Application.Visible = True
    ObjDocument.MailMerge.OpenDataSource Name:=strSourceName, 
        With ObjDocument.MailMerge
            .Destination = wdSendToNewDocument
            .Execute Pause:=True
        End With


ObjDocument.Close wdDoNotSaveChanges
Set ObjDocument = Nothing
Set ObjApplication = Nothing

    Exit Sub

    MsgBox Err.Description
    Resume Exit_mergeDocument

End Sub 


I hope that this simple example might be helpful to you.


  • 5th November 2009: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Md. Marufuzzaman
Bangladesh Bangladesh
A well experienced leader with successful track record of software development, product innovations, brand management and corporate communication etc. Some successful product innovations have also achieved and awards “Most Valuable Professional” (MVP) at 2010 and 2011 by and also selected as a mentor of Published over 100 technical articles in various software development resource sites (i.e.,, Microsoft MSDN, and IEEE & IBM (In progress)) and various IT Forums, Blogs etc.

Over twelve years of professional experiences in ICT field having extensive experience in formulating corporate vision and long term strategy. Leading development related functions including design, development, services, data management and analytics, customer experience management, content services, digital analytics and optimization.I have also more than two years’ of strong experience in mobile-VAS (platform development).

An individual with results-driven approach and relentless in pursuit of excellence from a business and organizational standpoint.Honest, believes in transparency, commitment and teamwork.

Expertise: Software/Solution Architect, Research, MIS, Data Analytics, Data Mining, BI, SaaS platform base application development, Large scale Win32 Form/Web based business software solutions, Security, Enterprise applications development, integration, etc.

Technologies/Tools: Microsoft.Net version 05/08/10/12, Microsoft SQL Server version 7/2K/05/08/12/14 , Oracle version 10/11, MySql version 5.1, 5.5, 5.7, Visual C#, VB.NET, ASP.NET, API, MVC, WebAPI , WPF, WCF, PHP, Microsoft Power BI, SPSS, PS2, R, Add-In, Visual Basic etc.

.Net UI component: Telerik, DevExpress, Ext.Net.
Scripting language: JavaScript, AngularJS, node.JS.
Source control / Subversion: Git,SVN.
Development methodologies: Agile,RAD.
Project Management / Issues Tracking Tools: JIRA, ClockingIt.

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180618.1 | Last Updated 5 Nov 2009
Article Copyright 2009 by Md. Marufuzzaman
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid