Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 492
  • Last Modified:

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.
0
iteched1
Asked:
iteched1
  • 2
1 Solution
 
Rey Obrero (Capricorn1)Commented:
change this line

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

to

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 &"'"
0
 
iteched1Author Commented:
WOOT

That worked...figures...

Thanks!

(it was for "number" data type).

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

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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now