Reply
 
Thread Tools Display Modes
  #1   Report Post  
MHutcheson MHutcheson is offline
Junior Member
 
Posts: 1
Default Dynamic Subject Line Email Merge

I have a Word 2010 document linked to an Access 2010 data source. When a user clicks a button in Access, the Word document loads and performs a email merge using the below VBA code:

Private Sub Document_Open()
With ActiveDocument.MailMerge
.Destination = wdSendToEmail
.SuppressBlankLines = True
.MailSubject = "Your Refund " & ActiveDocument.MailMerge.DataSource.DataFields("Re turn_code").Value
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

End With
.Execute Pause:=False
End With
End Sub

However, as the .mailsubject part is not in the loop it is only retrieving the first Return Code. I have tried to integrate in the loop to no avail using this code:

Dim i As Integer
Private Sub Document_Open()
With ActiveDocument.MailMerge
.Destination = wdSendToEmail
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord

i = .DataSource.DataFields.Count

Do While i 0
.MailSubject = "Your Refund " & ActiveDocument.MailMerge.DataSource.DataFields("Re turn_code").Value
i = i - 1
Loop

End With
End With
End Sub

But keep receiving the message the data member (.DataSource) is not found.

Where am going wrong?

Regards,

Michael
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2007 Email Merge & Subject Line Arthur Shurn Mailmerge 2 August 8th 09 09:07 AM
How do I add a subject line to my Word email merge? Stephanie Microsoft Word Help 1 May 29th 08 06:07 AM
How do I get something in the email subject line for mail merge? Jill Mailmerge 1 April 17th 08 11:11 PM
Inserting a merge field in subject line of an email BenS Mailmerge 3 April 10th 08 09:57 AM
Merge Dynamic Email and Dynamic Letter Viona Mailmerge 3 November 29th 05 10:55 PM


All times are GMT +1. The time now is 10:09 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"