Solved

Word Mail Merge from Access Table Problem

Posted on 2010-08-22
2
501 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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

12 Experts available now in Live!

Get 1:1 Help Now