Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Reference a variable in HTML when sending an email from Access 2013

Posted on 2014-03-12
3
Medium Priority
?
615 Views
Last Modified: 2014-03-12
I have an Access (Access 2013) form which I use to send email out to about 350 people.  I put the html in a text box to send it out.  The VBA is as follows

-------------------
Private Sub cmdSend_Click()
        Dim mess_body As String
        Dim appOutLook As Outlook.Application
        Dim MailOutLook As Outlook.MailItem
        Dim rst As ADODB.Recordset
        Dim vCount
        Set appOutLook = CreateObject("Outlook.Application")
        Set MailOutLook = appOutLook.CreateItem(olMailItem)
        Set rst = New ADODB.Recordset
        Set rst.ActiveConnection = CurrentProject.Connection
           
        rst.CursorType = adOpenKeyset
        rst.LockType = adLockOptimistic
        rst.Source = "EmailSend"
        rst.Open options:=adCmdTable
                   
        vCount = 0
                   
            rst.MoveFirst
            Do Until rst.EOF
            Set appOutLook = CreateObject("Outlook.Application")
            Set MailOutLook = appOutLook.CreateItem(olMailItem)
            With MailOutLook
                .BodyFormat = olFormatRichText
                vEmail = rst("InternalEmail")
                vName = rst("Name")
                .To = vEmail
               
                .Subject = Me.Mess_Subject
             
                .HTMLBody = Me.mess_text
                    If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
                        .Attachments.Add (Me.Mail_Attachment_Path)
                    End If
                    '.DeleteAfterSubmit = True   'This would let Outlook send th note without storing it in your sent bin
                .Send
                'txtStatus.Value = "Email Gone"
                PauseIt 30
                'txtStatus.Value = "Next one"
                rst.MoveNext
               
            End With
            vCount = vCount + 1
            txtEmailCount = vCount
            Loop
           
            'MsgBox MailOutLook.Body
            Exit Sub
           
email_error:
            MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
            Resume Error_out
Error_out:
   
End Sub
------------------------------

The name of the text box is mess_text.  I would like to be able to add the name of the person the email is going to so I need to know if you can put a variable in the html code so that each time it loops and gets the email address it can also get the name.  Here is the html:

------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html>

<title>Phi Kappa Tau</title>

<head><center>
<img src="http://www.mediafire.com/imgbnc.php/fb4efed6d4c73da74f16d97c149249714d0fef645b94f90cace8e5612696bb2d4g.jpg" border="0">
</center>
</head>

<body>
<p>
<table width="80%" height="100%" align="center">
<tr><td><font face="sans-serif">

Dear Beta Omega Alum,
<p>

<p>
Faithfully Submitted,<br>
Scott Palmer

<p>
<BR CLEAR="ALL" />
<hr>
<p>
<table width="100%" align="center">
<font face="Sans-serif">
<tr><td align="center">
<a href="mailto:Webmaster@phitaualumni.org">Webmaster</a> |
<a href="http://phitaualumni.org/index.php">Phi Tau Alumni</a> | <a href="http://phitaualumni.org/AlumniWeekend.htm">Alumni Weekend</a>

</tr></td>
</font>

</table>

</body>

</html>
----------------------------

Thanks,
Scott
0
Comment
Question by:Scott Palmer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 total points
ID: 39924968
So instead of "Dear Beta Omega Alum", you'd like it to read "Dear John Smith"?

If so, then you could use a "token" in the HTML, and replace that after you get the name. It looks like your VBA code already gets the name here:

 vName = rst("Name")

If so, then change your HTML to something like this:

table width="80%" height="100%" align="center">
<tr><td><font face="sans-serif">

Dear <<name>>,
<p>

<p>

Open in new window

And then do this:

Dim sBody As STring
sBody = Me.mess_text
sBody = Replace(sBody, "<<name>>", vName)
.HTMLBody = sBody
0
 

Author Comment

by:Scott Palmer
ID: 39924992
Where do I put the additional code?
0
 

Author Closing Comment

by:Scott Palmer
ID: 39925060
I messed with it for awhile and got it to work.

Thank you very much,
Scott
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question