Word MailMerge to E-Mail

H

hgoslin

Hi
I have the following code on a button on an Access 2003 form to
mailmerge to e-mail. The make table query creates a temp table in
Access which is used as the datasource for the Mailmerge. The Word
document opens fine but when the Execute command runs, it mailmerges
to a New document, not to e-mail. If I remove the execute command,
and manually choose the MailMerge to E-mail button on the MailMerge
toolbar in Word, it runs the merge correctly. Can anyone help
automate the MailMerge to e-mail part of this code?

I am using the ClickYes App to get around the Outlook security issue.

Private Sub cmdMMInv_Click()
DoCmd.SetWarnings False
Dim objWord As Object
Dim stDocName As String

If IsNull(DLookup("Name", "MSysObjects", _
"Name='TempInvoice' And Type IN (1,4,6)")) Then
DoCmd.DeleteObject acTable, "TempInvoice"
On Error Resume Next
End If

stDocName = "qryInvoices"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Set objWord = GetObject("e:\ISASA\Invoice Merge.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True


' Set the mail merge data source as the Corporate Members database.
objWord.MailMerge.OpenDataSource _
Name:="e:\ISASA\CORPORATE MEMBERS.mdb", _
LinkToSource:=True, _
Connection:="TABLE TempInvoice", _
SQLStatement:="SELECT * FROM [TempInvoice]"

objWord.MailMerge.MailAddressFieldName = "Email"
objWord.MailMerge.MailSubject = "Corporate Membership Invoice"
objWord.MailMerge.MailAsAttachment = True
objWord.MailMerge.Destination = wdSendToEmail
objWord.MailMerge.Execute

DoCmd.SetWarnings True

End Sub
 

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