Home  Fees/Services  Access Templates  Tutorials  Access Download  Articles  Search  Contact  Privacy  Links

Access VBA Tutorial
   
Access Programming Examples
MS Word Mail Merge With Access

Access Mail Merge Method Visual Basic Tutorials for Access 2007 VBA
Access 2007 Tutorial>Visual Basic Tutorial>Mail Merge Download VBA Tutorials  



Age Calculation
VBA Change Case
Calculate Running Sum
Concatenate Records
VBA CreateQueryDef
Database Path
Detail-Master Update
Field Validation VBA
Field Value New-Old
FindFirst Recordset
Get Version Number
VBA Global Parameters
VBA Global Variables
Labels as Links
VBA Outlook Email
List Box Files List
VBA Mail Merge
OutputTo Crosstab
Read Email Access
Sort Recordset
VBA Recordset Filters
Reference Form Field
RTF Report Email
VBA Select Case
VBA Transaction Processing

Visual Basic Function Examples


Visual Basic Mail Merge using MS Word Bookmarks

Using VBA to perform Microsoft Word mail merge give you the ultimate control and alleviates the need to jump to Microsoft Word to perform the mail merge.

To accomplish this task you'll need to create a Word template document with bookmarks inserted in the database field locations.  These bookmarks will represent the variable part of the document.

Next create an Access form with a button called Enveloppe.  And, create an on click event as shown below.  You'll need to customized the PathDocu line to match you particular setup.

Private Sub Enveloppe_Click()

Dim MyWord As Word.Application
Dim PathDocu As String

If Me.NomPers <> "" And Me.Prénom <> "" Then
    Set MyWord = New Word.Application
    PathDocu = "C:\Documents and Settings\BENOIT\Mes                           documents\Word\IFFC\BaseDeDonnée\Documents\"

With MyWord
    .Documents.Open (PathDocu & "Env22x10.doc")
    '.ActiveDocument.Bookmarks("date").Range.Text = & _
        Format(Date, "dd mmmm yyyy")
    .ActiveDocument.Bookmarks("nom").Range.Text = Me.NomPers
    .ActiveDocument.Bookmarks("prénom").Range.Text = Me.Prénom
    If Me.Adresse <> "" Then
        MyWord.ActiveDocument.Bookmarks("adresse").Range.Text = & _
        Me.Adresse
    If Me.Adresse2 <> "" Then
        MyWord.ActiveDocument.Bookmarks("adresse2").Range.Text & _
        = Me.Adresse2
    If Me.CodePostal <> "" Then
        MyWord.ActiveDocument.Bookmarks("codepostal").Range.Text &_
        = Me.CodePostal
    If Me.Ville <> "" Then MyWord.ActiveDocument.Bookmarks("ville").Range.Text =Me.Ville
    If Me.Pays <> "" Then MyWord.ActiveDocument.Bookmarks("pays").Range.Text = Me.Pays
' si vous désirez utiliser plusieurs fois les mêmes données, vous devez
' créer des signets différents

.Visible = True
End With
DoEvents
Set MyWord = Nothing
End If
On Error GoTo Err_Enveloppe_Click

Exit_Enveloppe_Click:
Exit Sub

Err_Enveloppe_Click:
MsgBox Err.Description
Resume Exit_Enveloppe_Click

End Sub
 

Contributed by Benoit Mann




Contact Information

Programming Visual Basic Tutorial

Access Visual Basic/VBA/VBScript/VB6 2007 2003 2000