|
Question : 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.
|
|
Answer : Print Word 2003 document from Access 2003 form with contents of current record.
|
|
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 &"'"
|
|
|