Mail Merge

G

Grant Reid

Hi

I hope someone out there can help me. I'm busy with a POC which requires an
Email mail merge via Word with the Email addresses for the recipients coming
from a table within a MS SQL database.

I attempted to record a macro, this initial attempt to record the macro was
succesful and mail was actually sent to the desired recipients. However,
when I attempted to run the recorded macro again I got the following error;
"Mail Merge - Record 1 contained too few data fields", followed by the
following; "Word cannot merge documents that can be distributed by mail or
fax without a valid mail address. Choose the Setup button to select a mail
address data field"

It is obvious to me that the recorded macro did not actually record the
address field info that I entered during the mail merge wizard, see recorded
macro below......

Sub Macro1()
ActiveDocument.MailMerge.OpenDataSource Name:= _
"C:\Documents and Settings\grantr.EMPIRE\My Documents\My Data
Sources\grantntsrv SIM Recipients.odc" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="",
_
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False,
_
Format:=wdOpenFormatAuto, Connection:= _
"Provider=SQLOLEDB.1;Password=sybase;Persist Security Info=True;User
ID=sa;Initial Catalog=SIM;Data Source=grantntsrv;Use Procedure for
Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=GRANTNTSRV;Use
Encryption for Data=False;Tag with column c" _
, SQLStatement:="SELECT * FROM ""Recipients""", SQLStatement1:="", _
SubType:=wdMergeSubTypeOther
With ActiveDocument.MailMerge
.Destination = wdSendToEmail
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
End Sub

The table name is "Recipients" and the Email addresses are contained in a
field named "Addresses". I wish I could do this myself, but I need to
deliver on this ASAP due to the time constraints imposed by the POC
delivery.

Kind Regards - Grant
 
D

Doug Robbins

You need to use the .MailAddressField name property to specify the field
that contains the email address as in the following example from the Help
File:

With Documents("FormLetter.doc").MailMerge
.MailAddressFieldName = "Email"
.MailSubject = "Amazing offer"
.Destination = wdSendToEmail
.Execute
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Grant Reid

Hi Doug

Thank you very much for your response. I'll give your suggestion a whirl, it
certainly sounds logical.

Kind regards and many thanks - Grant
 

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