Solved

Word Mail Merge from Access Table Problem

Posted on 2010-08-22
2
506 Views
Last Modified: 2012-05-10
I am trying to merge the value from an Access 2007 table to a Word document mail merge.  The table will only have one record.  The word document    Quote.doc is set up with the fileds and is pointed at the database  C:\Documents and Settings\All Users\Desktop\QuoteMaster.accdb

When the code runs, I receive an error in Word:
Could not find file C:\Documents and Settings\All Users\Desktop\Quotes.mdb'.

in Access, I get a Visual Baisc Error:
Run-time error '5922':
Word was unable to open the data source.

When I click debug, the following is highlighted:
objDoc.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\All Users\Desktop\Quotes\QuoteMaster.accdb", _
LinkToSource:=True, Connection:="TABLE tblSendQuote", _
SQLStatement:="SELECT * FROM tblSendQuote]"


Any help would be appreciated.


Private Sub cmdPrintQuote_Click()
Dim FILENAME As String
Dim objWord As New Word.Application
Dim objDoc As Word.Document
'Make Word visible
objWord.Application.Visible = True
'Sets the Word document to do the mail merging
Set objDoc = objWord.Documents.Open("c:\Quotes\Quote.doc")
objWord.Application.Visible = True
'Set the mail merge data source
objDoc.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\All Users\Desktop\Quotes\QuoteMaster.accdb", _
LinkToSource:=True, Connection:="TABLE tblSendQuote", _
SQLStatement:="SELECT * FROM tblSendQuote]"

objDoc.MailMerge.Destination = wdSendToNewDocument
objDoc.MailMerge.Execute
    
FILENAME = "Test File.doc"
objWord.Application.Documents(1).SaveAs ("C:\Quotes\" & FILENAME)
objWord.Application.Documents(2).Close wdDoNotSaveChanges
objWord.Application.Documents(FILENAME).Close
    
Set objWord = Nothing
Set objDoc = Nothing
End Sub

Open in new window

0
Comment
Question by:Scamquist
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
GrahamMandeno earned 500 total points
ID: 33497952
It appears you have an unmatched bracket in line 14.  Either delete the closing bracket or add an opening bracket before tblSenQuote.
--
Graham
0
 
LVL 1

Author Closing Comment

by:Scamquist
ID: 33498062
I am not going to admit how much time I spent monkeying around with this.  Some times it just takes another set of eyes to see the obvious.  Thank you so much for the assist.  

Steve

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to Use an Access DB to run a job forever 6 62
Access Query: Text to Date 10 33
MS Access Error Handling 6 30
MS Access populate a field based on 2 other form fields 14 36
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

730 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