Solved

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

Posted on 2014-03-12
3
600 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:ScootterP
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 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:ScootterP
ID: 39924992
Where do I put the additional code?
0
 

Author Closing Comment

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

Thank you very much,
Scott
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

820 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