Link to home
Start Free TrialLog in
Avatar of iteched1
iteched1Flag for United States of America

asked on

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.

Thanks!

Ed.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of iteched1

ASKER

WOOT

That worked...figures...

Thanks!

(it was for "number" data type).

Ed.
Other than this site...is 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.