By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

Word XP Mail Merge Problem

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Cancel this request guys - I finally got it working. However, then I ended
up with another problem, which I've posted separately ... sure could use
some help on that!
"Shannon Rotz" <sr***@shaw.ca> wrote in message
news:PSjcd.758726$gE.634372@pd7tw3no...
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

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.