UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Emailing Merged Document Mix Up, Any Version    
 
   
andywal6
post Feb 7 2019, 11:13 AM
Post#1



Posts: 142
Joined: 11-January 08



Hey Guys
I've cobbled together the Macro below to Merge word doc and send out as html email.
The email address is one of the merge fields called 'CustEmail' but am having trouble with the code reference.
The code after '.MailAddressFieldName'
It's just a little mixed up.
Can anyone help me to sort it out.
Many thanks for viewing.

CODE
Sub SendMergedDocByEmail()

    With ActiveDocument.MailMerge
        .Destination = wdSendToEmail
        .MailAddressFieldName = ActiveDocument.MailMerge.DataSource.DataFields("CustEmail").Value   '**This bit!**
        .MailSubject = "Your Documents as promised"
        .SuppressBlankLines = True
        .MailAsAttachment = False
        .MailFormat = wdMailFormatHTML
        With .DataSource
            .FirstRecord = wdDefaultFirstRecord
            .LastRecord = wdDefaultLastRecord
        End With
        .Execute Pause:=False
    End With
End Sub
Go to the top of the page
 
June7
post Feb 7 2019, 05:04 PM
Post#2



Posts: 807
Joined: 25-January 16



Is this code in Access module? Not seeing data source opened.

Following appears to be a good example https://rtmccormick.com/2015/11/23/automati...VBA-and-access/





--------------------
Attachments Manager is below the edit post window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
DEBUG! DEBUG! DEBUG! http://www.cpearson.com/Excel/DebuggingVBA.aspx
Go to the top of the page
 
andywal6
post Feb 7 2019, 05:14 PM
Post#3



Posts: 142
Joined: 11-January 08



HI June7
It will be a Macro in Word Normal template, called by an icon in the QATB.
Andy
Go to the top of the page
 
June7
post Feb 7 2019, 05:20 PM
Post#4



Posts: 807
Joined: 25-January 16



The only example I can find simply references the field name:

.MailAddressFieldName = "CustEmail"



--------------------
Attachments Manager is below the edit post window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
DEBUG! DEBUG! DEBUG! http://www.cpearson.com/Excel/DebuggingVBA.aspx
Go to the top of the page
 
andywal6
post Feb 8 2019, 05:43 AM
Post#5



Posts: 142
Joined: 11-January 08



Many thanks June7

All done now and the final Macro is below.

CODE
Sub SendMergedDocByEmail()
    '*** Macro to Automate Merge and Send by Email ***
    '*** (CustEmail) on line 4 is the name of the merge field in your document ***
    Dim strSend
    With ActiveDocument.MailMerge
        .Destination = wdSendToEmail
        .MailAddressFieldName = "CustEmail"
        strSend = InputBox("Enter a Subject line or Click [OK] to accept the Default", "Enter a Subject line", "Your Documents as promised")
        If strSend = "" Then Application.Quit SaveChanges:=wdDoNotSaveChanges
        .MailSubject = strSend
        .SuppressBlankLines = True
        .MailAsAttachment = False
        .MailFormat = wdMailFormatHTML
        With .DataSource
            .FirstRecord = wdDefaultFirstRecord
            .LastRecord = wdDefaultLastRecord
        End With
        .Execute Pause:=False
    End With
    Application.Quit SaveChanges:=wdDoNotSaveChanges
End Sub


Regards
Andy.........
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    21st September 2019 - 12:18 AM