Word XP MailMerge from Access - Problem

S

Shannon Rotz

I'm trying to automate Word XP from Access XP with the following function.
The sqlstmt argument is "Select * from [mytable] where [criteria]". I
understand that Microsoft Word mailmerge changed its default data source to
OLEDB, so I took a look in the KB on how to do this. According to Q285332,
my function should work - but it doesn't! I keep getting "Cannot open data
source" or the "Confirm data source" dialog box. I have tried this with and
without the Subtype argument.

Am I missing something?


Shannon

--------------------------------------------------------------------------

Public Function WordXP_letter(doc_name As String, sqlstmt As String,
AutoMerge As Boolean, Optional strQuery As String)
'On Error GoTo err_word_letter

Dim mywrd As Word.Application
Dim mydoc As Word.Document

'Stop
Set mywrd = New Word.Application

Set mydoc = mywrd.Documents.Add(doc_name)
mywrd.Visible = True
With mydoc.MailMerge
.MainDocumentType = wdFormLetters
.OpenDataSource NAME:=CurrentDb.NAME, SQLStatement:=sqlstmt,
subtype:=wdMergeSubTypeWord2000
.Destination = wdSendToNewDocument
End With
If AutoMerge = True Then
mydoc.MailMerge.Execute True
mydoc.Close wdDoNotSaveChanges
End If
mywrd.Activate

'mywrd.Documents("Document1").Close wdDoNotSaveChanges
Set mydoc = Nothing
Set mywrd = Nothing
Exit Function

err_WordXP_letter:
Select Case Err.Number
Case Is = 5151
MsgBox ("Cannot find the template '" & doc_name & "'. Please
re-add it to the folder and try again.")
Case Is = 4198
Resume Next
Case Else
MsgBox Err.Number & " - " & Err.Description
Exit Function
End Select

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top