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

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.


Who is Participating?
Rey Obrero (Capricorn1)Commented:
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 &"'"
iteched1Author Commented:

That worked...figures...


(it was for "number" data type).

iteched1Author Commented:
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?

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

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.