Question : Word Mail Merge from Access Table Problem

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.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
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

Answer : Word Mail Merge from Access Table Problem

It appears you have an unmatched bracket in line 14.  Either delete the closing bracket or add an opening bracket before tblSenQuote.

--
Graham

Random Solutions  
 
programming4us programming4us