Print Word 2003 document from Access 2003 form with contents of current record.

Posted on 2007-10-16
Last Modified: 2013-11-28
Hi Experts,

Problem:  Create button that prints a word document with information from the current record.
Programs:  MS Access 2003 and Word 2003

What I have so far:

A button with a click event (I've added line numbers):

1.  Private Sub Command61_Click()
2.     Dim objWord As Word.Document
3.     Set objWord = GetObject("C:\MyMerge.doc", "Word.Document")
4.     ' Make Word visible.
5.     objWord.Application.Visible = True
6.     ' Set the mail merge data source as the RCIMS database.
7.     objWord.MailMerge.OpenDataSource _
8.      Name:="C:\Documents and Settings\epack\My Documents\Access Databases\RCIMS.mdb", _
9.          LinkToSource:=True, _
10.          Connection:="Table Contacts", _
11.         SQLStatement:="SELECT * From [Contacts] WHERE ContactID" = Me.ContactID
12.     ' Execute the mail merge.
13.     objWord.MailMerge.Execute
14.  End Sub

What happens:

1.  When the button is clicked the word document is opened (it has merge data from when I created the document).
2.  I close the document and get a window:

Run time error "13":
Type Mismatch

When I select debug the code appears with lines 7-11 highlighted and an arrow on line 11.

Based on what I'm finding I'm pretty close (hopefully)...

But I've been out of the coding world a while an obviously am missing something...LOL.


Question by:iteched1
    LVL 119

    Accepted Solution

    change this line

    SQLStatement:="SELECT * From [Contacts] WHERE ContactID" = Me.ContactID


    SQLStatement:="SELECT * From [Contacts] WHERE ContactID = " & Me.ContactID

    assuming contactID is number type of data

    if text use this

    SQLStatement:="SELECT * From [Contacts] WHERE ContactID = '" & Me.ContactID &"'"

    Author Comment


    That worked...figures...


    (it was for "number" data type).


    Author Comment

    Other than this there a good resource book centered on MS Access and VB code?  Something that would, for example, show the complete syntax of the "select" command?


    Expert Comment

    I'm finding the Access 2003 VBA Programmers Reference to be most useful - I auume the 2007 version is as well.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
    In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now