Solved

Word Mail Merge from Access Table Problem

Posted on 2010-08-22
2
503 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now