HTML Code for Email Body Text


I am using an Access form and VBA to send multiple emails at the same time. Everything is working fine. However, now I would like to include some HTML code in the Email body as I would like to put a URL link as part of the text message to the recipient.

An idea of the HTML code I'd like to use in the email body is:

Please follow this link to my website

Anyone can give me any ideas of how I can do this?

Below is the current VBA code I'm using:

 Set objMessage = CreateObject("CDO.Message")
 Set rsEmail = CurrentDb.OpenRecordset("qryEmailList")

 Do While Not rsEmail.EOF
    strEmail = rsEmail.Fields("Email").Value   
    Set objMessage = New CDO.Message  
    strBodyText = "Email body text"
    objMessage.Subject = "Email subject title"
    objMessage.From = ""
    objMessage.To = strEmail
    objMessage.TextBody = strBodyText        

Set objMessage = Nothing
Set rsEmail = Nothing

Any feedback is greatly appreciated


Post your answer or comment

comments powered by Disqus
I need to use HTML template file as body in emails. The emails will be sent via Outlook 2010. The code I made is working well with .oft files, but these files are being received as plain text, although they are sent as HTML and although they appear fine in sent box.

After googling, I found that for some reason Outlook 2010 cannot use .oft files properly. A lot of people have the same problem as me and no one offered solution so far.

Therefore, I must use HTML file instead of .oft file. Could you please help me change the code so it does everything the same, only uses external HTML file instead of external .oft file?

Additional, it would be quicker solution if you know how to send .oft file to be received as HTML and not plain text file. That is alternative, but I suspect it is not possible.

	Private Sub dgmSlanje_Click()

Dim OutlookApp As outlook.Application
Dim Poruka As outlook.MailItem
Dim objDoc As Object
Dim OutlookRecip As String
Dim strCustomer As String
Dim strHTML As String
Dim Putanja As String

Set OutlookApp = CreateObject("Outlook.Application")

Putanja = ctrOft
Set Poruka = OutlookApp.CreateItemFromTemplate(ctrOft)

strCustomer = "'' ("
strHTML = Replace(Poruka.HTMLBody, "%subfirstname%", strCustomer)

Poruka.BodyFormat = olFormatHTML

Set objDoc = Poruka.GetInspector.WordEditor
objDoc.Windows(1).Selection.Find.Execute strSender

'Poruka.DeferredDeliveryTime = #11/21/2011 10:15:00 PM#   Odredjuje vreme slanja

If Not ctrPrima.Value = "" Then
    Poruka.To = ctrPrima
End If

If Not ctrCc.Value = "" Then
    Poruka.CC = ctrCc
End If

If Not ctrBcc.Value = "" Then
    Poruka.BCC = ctrBcc
End If

If Not ctrTema.Value = "" Then
    Poruka.Subject = ctrTema
End If

Poruka.SendUsingAccount = outlook.Application.Session.Accounts.Item(cmbEAdrese)

  Set OutlookApp = Nothing
  Set Poruka = Nothing
  Set objDoc = Nothing
End Sub

Here we go...

Email comes in to Outlook with the body as colon delimited text (it's from a web site form fill). I want to import the email (easy, linked file). I then want to strip the body text into the 135 colon delimited fields, put the field into another table set up for the purpose and then delete the email. A button or event on the form showing the linked record would do, but fully automatic would be great.

I've read the boards and in theory I can strip the colons out with split function and create an array but how do I do that and then get the contents into a new a record on another table?


Nick Bridgens

two queries really.

1. i have code attached to this posting which emails data to a user. this all works fine no problems at all.
but the email sends anything from 1 record to 10.
does anyone know of syntax to put in that will make the email only pick up records that are not blank? I tried an if then else statement but the coding fell over.

at present I have titles for 10 records but obviously if the user only selects 2 records to email the others stay empty, which makes the email slightly cumbersome.

2. also does anyone know the syntax for making the text bold? so the resulting email will have bold fonts?

many thanks


Have code that sends an email and also concatenates a string creating a list within the email body but the names within the code are all concatenated together. What would be the syntax to get a return in there for ease in reading?

"select distinct Nz([fname], 'Unknown) from myTable"

I've tried:

"select distinct Nz([fname], 'Unk') " & vbCrlf & " from myTable"
"select distinct Nz([fname], 'Unk') " & chr(13) & chr(10) & " from myTable"


I just started programming in VB and have little experience in programming and I am in need of some help. I have generated the following code to separate one large report into different sections based on agency information and it saves these separates reports into a file. I want to email each agency their report but I have over a 1000 agencies and don’t want to email each individually. I know I can use the SendObject Command in my code to email these reports as attachments but I don’t know how I would incorporate it into my code. I don’t have the email of the agencies as part of my data. Do I have to set up another table with email addresses to accomplish this? Does anyone have any suggestions?

Option Compare Database
Option Explicit

Public Sub PrintAgencyReport()

Dim dbs As Database
Dim tdf As TableDef
Dim rstAgency As Recordset
Dim strWhere As String
Dim strReportName As String
Dim strFileName As String
Dim rstTestForRecords As Recordset
Dim strWhereTest As String
' Return reference to current database
Set dbs = CurrentDb

' Return reference to Agency table
Set tdf = dbs.TableDefs!Table1

' Open the AgencyList table containing agencies
Set rstAgency = dbs.OpenRecordset("Table1")

' Loop through AgencyList table to get the agency _
parameter for the report and path to send report
With rstAgency
Do Until .EOF
strReportName = "Report1"
strWhere = "[Agency]='" & rstAgency![Agency] & "'"
strFileName = "C:FDLEfiles" & rstAgency![Agency] & ".rtf"
strWhereTest = "Select * From Table1 Where " & strWhere
Set rstTestForRecords = dbs.OpenRecordset(strWhereTest)
If rstTestForRecords.BOF And rstTestForRecords.EOF Then
DoCmd.OpenReport strReportName, acViewPreview, , strWhere
DoCmd.OutputTo acOutputReport, strReportName, "RichTextFormat(*.rtf)", strFileName
End If
End With
End Sub

Thanks For The Help!

Hi guys,
I'm a newbee here. Am also newbee in access. I have started a database for our company assets using Access. So far things are going right on track when suddenly i'm faced up with a problem in determining the right VB code.
In my Menu I have 4 buttons: one for viewing a report, one for printing a report, then one for emailing a report, and finally sending a report to file. I was able to successfully perform the viewing and printing a report. When i decided to add the emailing and sending a report, I got lost. I dont know anymore how to go about it. Can anybody help me? I just need to know how to go about emailing and sending a report. Here is my code:

Option Compare Database ' Use database order for string comparisons.
Option Explicit ' Requires variables to be declared before they are used.

Sub PrintReports(PrintMode As Integer)
On Error GoTo Err_CommandPrevReport_Click
' This procedure used in Preview_Click and Print_Click Sub procedures.
' Preview or print report selected in the ReportToPrint option group.
' Then close the Print Sales Reports Dialog form.

Dim strWhereCategory As String
strWhereCategory = "Plnt_Name = Forms![Plant Data Option Print Form]!PlantListBox1"
Select Case Me!ReportToPrint1
Case 1
'DoCmd.OpenReport "SL Summary Report", PrintMode

If IsNull(Forms![Plant Data Option Print Form]!PlantListBox1) Then
DoCmd.OpenReport "SL Summary Report", PrintMode
DoCmd.OpenReport "SL Summary Report", PrintMode, , strWhereCategory
End If

Case 2

If IsNull(Forms![Plant Data Option Print Form]!PlantListBox1) Then
DoCmd.OpenReport "Fixed Assets Per Plant Report", PrintMode
DoCmd.OpenReport "Fixed Assets Per Plant Report", PrintMode, , strWhereCategory
End If
End Select

Exit Sub
Resume Exit_CommandPrevReport_Click
End Sub

Private Sub CommandClose_Click()
' This code created by Command Button Wizard.
On Error GoTo Err_CommandClose_Click
Dim stDocName As String
Dim stLinkCriteria As String

' Close form.
stDocName = "Main Menu"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit Sub

Resume Exit_CommandClose_Click
End Sub

Private Sub CommandPrevReport_Click()
' Preview selected report. This procedure uses the PrintReports
' Sub procedure defined in (General) section of this module.

PrintReports acPreview

End Sub

Private Sub CommandPrintReport_Click()
' Print selected report. This procedure uses the PrintReports
' Sub procedure defined in (General) section of this module.
PrintReports acNormal

End Sub

Private Sub ReportToPrint1_AfterUpdate()
' Enable SelectCategory combo box if user selected Sales by Category
' report.
Const conPlantData = 2
If Me!ReportToPrint1.Value = conPlantData Then
Me!PlantListBox1.Enabled = True
Me!PlantListBox1.Enabled = True
End If

End Sub

Private Sub PlantData_GotFocus()
End Sub

Private Sub PlantListBox1_BeforeUpdate(Cancel As Integer)
End Sub


How do you change to a new line in the body text? Because I want to have a simple table output.

I created this code to change some text on my form to indicate if the name record is a current card holder or not. It's overly complicated because all cards expire at the end of the year, but if they applied within the last two months of the year then we give them a card that will last until the end of next year.

After having made it though, I'm not sure what even to put it under!

Also, I'm not sure if the 12/31/[datepart("yyyy",now)] syntax is correct. My background has nothing to do with VB or Access if you couldn't tell...

Any help would be greatly appreciated!

	    Dim datecount As Integer    'assigned the # of days between issue date and end of year
    Dim expirecount As Integer  'assigned the # of days before card expires
    Dim issuedate As Date
    issuedate = Me.frmNameSubApp.Form!appIssueDate
    datecount = DateDiff("d", issuedate, 12 / 31 / [datepart("yyyy",now)])
        If datecount < 60 And datecount > 0 Then
            expirecount = 365 + datecount
            expirecount = 365 - DateDiff("d", Now, 12 / 31 / [datepart("yyyy",now)])
        End If
    If issuedate = Null Then
        Text27.Text = Null
    ElseIf DateDiff("d", issuedate, Now) >= expirecount Then
        Text27.Text = "Current Card Holder"
        Text27.Text = "Not Current"
    End If

Dear all,

Just want to share the solution I built for creating of high-quality HTML reports in MS Access, describe workarounds, which I had to implement as well as to provide a link to real tool which implements this solution for MS Access 2007 / 2010 (Meeting minutes, Issues, Risks, Agreements, Actions, Projects Tracking Tool).

There is nothing extremely new in my solution; similar approach is described previously

However I give a link to real implementation as well as describe workarounds, which I had to use.

Problem description:

This is a common knowledge, that even though available, the export to HTML from MS Access report is not working well. Such export will never produce a high-quality HTML
So, the only solution to save Access report outside of MS Access is to PDF it. This solution has disadvantages:
It is difficult to edit or comment PDF or to copy and paste information from it. afterwards. Hence it is difficult to others either to use data from this report or to provide a feedback on it. If you send it via email, you have to send it as attachment. Now days, when everybody is using mobile phones to read emails, it creates extra complications. Besides, if you email information as attachment, you can’t use MS Outlook search engine to search for information within attachment.


Even though MS Access can’t export reports to HTML well, the structure of Access report is very suitable to create an HTML code itself.

The code of HTML page has header, body and footer and MS Access report has the same elements.

Table in HTML has also sort of header body and footer, hence it is very easy to create HTML code for table using subreports: e.g.


Header 1
Header 2


cell 1
cell 2


So, the trick is to create report which, when saved as text format, would create HTML code.

As example, if you want to have a header at the top of HTML report, you have to create the following text in MS Access report:

Header text

Tricks, issues and workarounds
There are several tricks though, which one has to use.

1) Use CSS
Use CSS in your HTML code, it will make the HTML code much compacter.

2) Rich formatted Memo field
In Access 2007 there is a nice feature of rich format for Memo field, which is in reality saved as html text in Access. It is very well compatible with our approach. So, when placing control on MS Access report for this rich-formatted memo field, just set it’s property to text (not rich text), this will produce a direct HTML code into your report for rich-formatted memo field.

3) Issue, when exporting to text.
There is an issue, that export of complex reports (with subreports and a lot of information etc) to text formal does not work well always, there seems to be a bug in Access. Sometimes lines get mixed, sometimes information gets dropped completely.

I found, that exporting to rich format works much better. So the trick is to export Access report 1st to rich format and then use office automation of MS Word from MS Access to open this .*rtf file and save it to text format with *.html extension. It reality it works quite well and user does not notice anything as MS Word opens in background.

You can find MS Access 2007/2010 database, which uses this approach to produce HTML reports in sourceforge if you search for the word "MIRAAPT" in Google.

Note: MIRAAPT stands for Meeting Minutes, Issues, Risks, Agreements, Actions, and Projects Tracking.



P.S. by the way, if somebody is interested in my tool and wants to co-develop – you are more than welcome to get in contact with me.

Hey guys,
I can get this 1st script to auto-generate an email (outlook 2010), and I can get the 2nd script to open an unaddressed email with my report in the body, but I can't get the exporthtml script integrated into the MissingInfoRouteMessage script. Any tips?
The script I have for the Access 2007 generated email is:
Private Sub MissingInfoRouteMessage()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim str_SQL As String
Dim str_SQL1 As String
Dim varX As Variant
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

Export = exporthtml '**(this being my pathetic attempt at merging, see next script)
varX = DLookup("[E-Mail]", "t_Routing", "[Mfg_Cd] is not null")
With objOutlookMsg

'Set objOutlookAttach = .Attachments.Add(file path)

Set objOutlookRecip = .Recipients.Add(varX)
objOutlookRecip.Type = olTo
Set objOutlookRecip = .Recipients.Add("")
objOutlookRecip.Type = olCC
.Subject = "International Authorization"
.HTMLBody = "Hi Team,
Please let me know if the following orders are okay to approve." & vbCrLf & vbCrLf & Export
.Importance = olImportanceHigh

For Each objOutlookRecip In .Recipients
If Not objOutlookRecip.Resolve Then
End If
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub

And this HTML script that converts a report to text to put in the body of an email:
Function exporthtml()
Dim strline, strHTML
Dim OL As Outlook.Application
Dim MyItem As Outlook.MailItem
Set OL = New Outlook.Application
Set MyItem = Outlook.Application.CreateItem(olMailItem)

DoCmd.OutputTo acOutputReport, "Report-q_Workflow", acFormatHTML, "file path"

Open "file path" For Input As 1
Do While Not EOF(1)
Input #1, strline
strHTML = strHTML & strline
Close 1
' If OL2002 set the BodyFormat
If Left(OL.Version, 2) = "10" Then
MyItem.BodyFormat = olFormatHTML
End If
MyItem.HTMLBody = strHTML
End Function

The next issue I'm having is that I need the email to send only specific parts of the report to specific email addresses. I.E. 6 tuples might get sent to one address, 4 tuples to a 2nd address, and so on. But I'd rather get this initial problem solved first (I welcome tips with this though).
Thanks! Let me know if I didn't properly explain the background.

Hi I have put some code together from different threads, it works great... my issues are
1. the myBody text keeps going below my auto signature in lotus notes
2. I want to only have selected records from Datasheet view in the text, I tried to use RecordsetClone but it selects all records. The Data will be in alphabetical order so they can use shift to highlight certain records.

	Private Sub EmOneWay_Click()
Dim Notes As Object
Dim Maildb As Object
Dim objNotesDocument As Object
Dim objNotesField As Object
Dim mysubject As String
Dim mysendto As String
Dim myBody As String
Dim rs As DAO.Recordset
Set rs = Forms!frm_OneWayOffhire!subfrm_OneWay.Form.RecordsetClone
Do While Not rs.EOF
Dim Cntr As String
Dim TS As String
Dim Port As String
Dim ETA As String
Cntr = rs!Container_No
TS = rs!Type_Size
Port = IIf(IsNull(rs!Port), "", rs!Port)
ETA = IIf(IsNull(rs!Arrival), "", rs!Arrival)
myBody = myBody & vbCrLf & Cntr & "    " & TS & "    " & "Port" & "    " & Port & "    " & "ETA:" & "    " & ETA & Chr(13)
mysubject = "Sub-leased units to be redelivered"
mysendto = Me.txtemail 'or you can use Me.txtemail for example
Set Notes = CreateObject("Notes.NotesSession")
Set Maildb = Notes.GETDATABASE("", "")
Call Maildb.OPENMAIL
Set objNotesDocument = Maildb.createdocument
Set objNotesField = objNotesDocument.appenditemvalue("Subject", mysubject)
Set objNotesField = objNotesDocument.appenditemvalue("SendTo", mysendto)
Set objNotesField = objNotesDocument.createrichtextitem("Body")
Call objNotesDocument.REPLACEITEMVALUE("", , "Body", myBody)
Set Workspace = CreateObject("Notes.NotesUIWorkspace")
Call Workspace.EDITDOCUMENT(True, objNotesDocument)
Dim UIdoc As Object
Call UIdoc.GOTOFIELD("Body")
Body1 = "Good Day," & vbCrLf & vbCrLf & "Could you please advise offhire details for the following units:" & vbCrLf & vbCrLf
Call UIdoc.InsertText(Body1)
'Insert some carriage returns at the end of the email
Call UIdoc.InsertText(vbCrLf & vbCrLf)
MsgBox "An email has been generated with Lotus Notes. Please pull up your LotusNotes window to view and send the email. Thank
End Sub

I have been working on an address book of customer details and contact information with the option to email one contact or a list of selected contacts (via check box to be included and a make table query that populates the BCC field), these contacts have been seperated into catagories of wholesale, retail, suppliers...etc. The email code I have used is not mine, though I have tweaked it to suit my needs.

I have been looking for the code to on the forum to make the body of the email include a generic html file for the users of the DB stored in a specific folder on the c: of each users computer. Pasted Below is the code I have used to generate the email and populate the BCC field.

I know how to send the html file as an attachment, but that is not what I have been looking for.

	Private Sub cmdSendEmailToAll_Click()
'Use this code in the build event part of a command button
'to send EMail to everyone in a table having an EMail address.
'This saves you the time and trouble of using contacts in Outlook.

'The first problem I encountered was configuring access to 'talk to' Outlook.
'A helpful person told me to try the following, which I did, and it worked!!

'Open a code window and make sure the following are checked (Tools--->References)
'They are not all checked by default, so you will have to do it.
    'Visual Basic for Applications
    'Microsoft Access 9.0 Object Library
    'OLE automation
    'Microsoft ActiveX Data Objects 2.1 Library
    'Microsoft DAO 3.6 Object Library
'Change table names and field names in this code to fit your table structure

'Every record in the table you reference must contain an EMail address field.
'In this code, I use a field called EMailAddr.
'Open Outlook and make sure the bcc field is displayed before trying to use the program.
'After opening Outlook, minimize it.  The code will run a lot quicker if you don't have to wait for outlook to open.

'If all records in your table do not contain an EMail Address, then
'you should run a MakeTable query first and create a new table.
'I use one field table, with EMailAddr as the field name
'The only records are those having an EMail Address
'Reference the new table in this code.
'The table will be deleted and recreated each time you send an EMail.

'If you do not have to run the MakeTable query (because everyone in your main table has an EMail address)
'comment out the next three lines:

    Dim strDocName As String
    strDocName = "tblEmailIncluded"
    DoCmd.OpenQuery "qryEmailIncluded"

On Error GoTo ErrHandle

    Dim dbs         As DAO.Database
    Dim rst         As DAO.Recordset
    Dim strAddress  As String 'this creates the Email addresses
    Dim strTo       As String 'this is needed to populate the TO in the EMail
    Dim strCC       As String 'this is needed to populate the CC in the EMail
    Dim strBCC      As String 'this is needed to populate the BCC in the EMail
    Dim strSubject  As String 'this is needed to populate the SUBJ in the EMail
    Dim strBody     As String 'this is needed to populate a portion of the message text in the EMail
'The following code opens up a record set based on the table called tblVolunteers, which is my main table.
'Replace "tblVolunteers" with the name of the table containing the EMail Addresses.  Be sure to include the quotes.
    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("tblEmailIncluded", dbOpenSnapshot)
'I don't know if the following code works, as I never tested it.
    If rst.BOF = True And rst.EOF = True Then
        MsgBox "There must be an error in the query as there are no EMail Addresses listed!"
        GoTo ErrExit
    End If

    With rst
        .MoveFirst      'go to the first record
        strAddress = .Fields("EmailAddress").Value
        'replace EmailAddress with the name of your EMail field.  Be sure to use the quotes
        strBCC = strAddress
        .MoveNext   'get all subsequent addresses and separate each with a semi-colon
        Do While .EOF = False
            strAddress = .Fields("EmailAddress").Value
            '*** Replace "EMailAddress" with the name of your field
            strBCC = strBCC & "; " & strAddress
    End With
    strTo = ""
    'replace with your own EMail address.  It will go into the TO field
    'Note: I put all addresses in the BCC field and mail it to myself as
    'this will protect the privacy of other peoples mail addresses
    'Each person will receive an EMail, without knowing who else got it
    'This is done for security reasons
    strCC = ""
    'The CC field will be left blank, unless you put something between the quotes
    strBCC = strBCC
    'All the EMail address, with a semi-colon separating them
    strSubj = ""
    'This will input a generic subject for your EMail.  If you don't
    'want a generic subject, just use the quotes, with nothing between them
    strBody = ""

    'Chr$(13) will insert a blank line in the subject of your EMail
    'Anything between the quotes will be inserted.  You can edit, as required before sending
    'If you want the subject to be blank, just put the quotes, with nothing between them

    DoCmd.SendObject , , , strTo, , strBCC, strSubj, , True
    'Note the above order.  This code fills in the TO, BCC, Subj, and Text blocks of the EMail form

    Exit Sub
    MsgBox Err.Description
    Resume ErrExit

End Sub

If anyone can help it would be greatly appreciated. Also If you would like to see how it works let me know.

Thanks in advance,


I receive around 300 mails daily with the following line in the message body


While the first field is always fixed with 11 letters other fields length vary. Can anyone suggest how to automate this to update / write in a database with four text fields. The email is always received from the same user (sender is same for example I have tried the facility available in Access 2007 but there we need to send a form and in the reply in HTML format the reply is sent and the same is processed. But in my case the mail is in simple text format.

Thanks in advance to all the experts. As this is my first post kindly guide me if already a solution exists for this. I have searched the forum before posting this but I might have missed it as the search words given by me might not have matched with any posts.

Greetings all,

I am currently in the process of creating a database with mass mailing functionality. I have basically completed everything however, I'm looking for a simpler way of creating the body of the message that can contain a template of sorts with data embedded in it from a table.

Code: ="Greetings, You are recieving this notification because you are listed as the owner for an AFE still in process:" & Chr(13) & Chr(10) & " " & Chr(13) & Chr(10) & " " & [ProjectDef] & " - " & [ProjectName] & " " & Chr(13) & Chr(10) & " " & Chr(13) & Chr(10) & " In order to facilitate new reporting requirements I will be needing a planned spend on all projects in process for Q2,Q3, and Q4 of this year. Also, if any spend will be pushed to next year, please indicate that as '2014 and beyond'. Please furnish all of the information on the attached spreadsheet. If the project listed is completed, please reply to this message with the MONTH/YEAR of completion and that will close your responsibility. If you have multiple projects, feel free to consolidate them on the spreadsheet." & Chr(13) & Chr(10) & " " & Chr(13) & Chr(10) & " Your reply is appreciated BY TUESDAY, APRIL 2nd 2013. If you have any questions, feel free to eMail me any time. " & Chr(13) & Chr(10) & " " & Chr(13) & Chr(10) & " Regards," & Chr(13) & Chr(10) & " " & Chr(13) & Chr(10) & " (closing signature)" This is my current label I have that is mapped to the email body. As you can see it is rather messy. I have used a utility like this with Apple in a Filemaker database that could do mass emails and it was MUCH easier. I could basically type at will and simply insert a variable wherever needed. IE

Code: (Greetings [customer], your order number is [order_no] and was shipped out on [ship_date]) Is there any such easier way to do this without having to submit to the draconian syntax in Text Boxes in Access?

I'm still a newbie when it comes to VBA so I was wondering if someone could direct me on how to accomplish this... I have a database where floor management input productivity updates on a quarterly basis and email them to upper management from the database. The email has a .rtf attachment. Upper management would prefer to get this information in the body of the email as opposed to an attachment because they use a blackberry. I'm not sure how to collect this information (stored in 2 different tables) and send it in the body of an email.

I am using the following (found on the net) to create the notes session and prepare the email:

'This public sub will send a mail and attachment if neccessary to the
'recipient including the body text.
'Requires that notes client is installed on the system.
Public Sub SendNotesMail(Subject As String, Attachment As String, Recipient As String, BodyText As String, SaveIt As Boolean)
'Set up the objects required for Automation into lotus notes
    Dim Maildb As Object 'The mail database
    Dim UserName As String 'The current users notes name
    Dim MailDbName As String 'The current users notes mail database name
    Dim MailDoc As Object 'The mail document itself
    Dim AttachME As Object 'The attachment richtextfile object
    Dim Session As Object 'The notes session
    Dim EmbedObj As Object 'The embedded object (Attachment)
    'Start a session to notes
    Set Session = CreateObject("Notes.NotesSession")
    'Next line only works with 5.x and above. Replace password with your password
    'Session.Initialize ("password")
    'Get the sessions username and then calculate the mail file name
    'You may or may not need this as for MailDBname with some systems you
    'can pass an empty string or using above password you can use other mailboxes.
    UserName = Session.UserName
    MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
    'Open the mail database in notes
    Set Maildb = Session.getdatabase("", MailDbName)
     If Maildb.ISOPEN = True Then
          'Already open for mail
     End If
    'Set up the new mail document
    Set MailDoc = Maildb.createdocument
    MailDoc.Form = "Memo"
    MailDoc.sendto = Recipient
    MailDoc.Subject = Subject
    MailDoc.Body = BodyText
    MailDoc.SaveMessageOnSend = SaveIt
    'Set up the embedded object and attachment and attach it
    If Attachment  "" Then
        Set AttachME = MailDoc.createrichtextitem("Attachment")
        Set EmbedObj = AttachME.EmbedObject(1454, "", Attachment, "Attachment")
        MailDoc.ReplaceItemValue "CreateRichTextItem", ("Attachment")
    End If
    'Send the document
    MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
    MailDoc.Send 0, Recipient
    'Clean Up
    Set Maildb = Nothing
    Set MailDoc = Nothing
    Set AttachME = Nothing
    Set Session = Nothing
    Set EmbedObj = Nothing
End Sub

I then call the following:

Sub QtrEmail()
DoCmd.OutputTo acOutputReport, "rptAMQtrUpt", _
acFormatRTF, "J:MFGShopAMQtrUpt.rtf", False
Dim stTomb As String
stTomb = ""
Call SendNotesMail("Quarterly Update", "J:MFGShopAMQtrUpt.rtf", stTomb, "Report attached", True)
End Sub

I gather I need to declare my "BodyText" as a variable.... I'm just not certain what all I need to do to get the information emailed without an attachment. Can anyone point me in the right direction? Thanks


I have a field in an Access form that I'm trying to put into the body of an email. It looks like there's a character limit of 752 characters for the body, regardless of the email client. Is there a better way of doing this:

Dim esssContent As String
esssContent = Me.eSSS.Text
Application.FollowHyperlink "mailto:?body=" & esssContent

I want to let the body text to not be limited by size and I want to be able to preserve and hard returns that were in the original field.


I have some code that attaches a report to an email. What I need to be able to do is make the body of the email's text bold and red, but I can't figure out how to do it! Can someone help??

Here is the code:
Private Sub Command3_Click()
Dim rptName As String
Dim bytchoice As Byte
Dim strmsg As String
Dim intoptions As Integer
Dim tmpdate As Date

strmsg = "Are you sure you want to send this report?"
intoptions = vbQuestion + vbYesNo
bytchoice = MsgBox(strmsg, intoptions)

If bytchoice = vbYes Then
tmpdate = InputBox("Enter date of Release")
rptName = "Release Summary Document - Walt"
DoCmd.SendObject acSendReport, rptName, acFormatRTF, InsertEmailAddressHere, , , "IMPORTANT: WALT Release Summary - " & tmpdate, "Important WALT Release Notice Attached. Please distribute to EVERY WALT User in Your Department. Changes are scheduled to be moved into Production on " & tmpdate & ".", False
If bytchoice = vbNo Then
Cancel = True
End If
End If
End Sub

I'm developing an Acess 2002 database for a client that will be used as the backend for a web site. Client wants to be able to enter text descriptions that will appear in web site. They need some minimal HTML Formatting (Bold, Underline, Italicize).

I have created a neat function that adds HTML formatting tags to the text in a text box. Works great. Now for the inexperienced user, I would really like to display a popup form with the formatted text as it would appear on the Web Site. I don't need to edit the formatted text, only to view it.

Does anyone know of a way to do this? Has anyone created an ACX to provide this?

Thanks in advance for your help. If anyone wants a copy of the function, please send me an email.

Almost there!

I built an email parser that finds text based on message formatting.

For example, the messages I parse have slashes in them as follows:


I simply parse the SUBJ line and end it with the // delimiter.

Works GREAT! How to do code it to find text that isn't separated by slashes?

Each message (Outlook email) has a date time group in the first few lines of text. i.e., 020226Z MAY 08. That reads 02 May, 0226am ZULU time. That is the last piece I need to parse and don't know how to tell it to look for that exact ASCII format.

(######Z LLL ##)

Any ideas on how to tell my parser to look for 12 characters in the same format as above, but will obviously be different in each message?

Thank you in advance. Couldn't get into my old account (deafmetal) but have been a routine user and fan of this forum since 2002. THANK YOU!!!

I need to know if it is possible to create a TextBox in the body of an email. Currently I am using HTML for the body of my email.

I have an email that I send out for Audit Findings. I would like some large text boxes in the email so they could fill out their responses and forward back the email to me. I could then copy and paste the the information in the textboxes where I need to.

Greetings all,

I am currently in the process of creating a database with mass mailing functionality. I have basically completed everything however, I'm looking for a simpler way of creating the body of the message that can contain a template of sorts with data embedded in it from a table.

You are recieving this notification because you are listed as the owner for an AFE still in process:" 
& Chr(13) & Chr(10) & " " & Chr(13) & Chr(10) & " " & [ProjectDef] & " - " & [ProjectName] & " " & Chr(13) & Chr(10) & " " &
Chr(13) & Chr(10) & 
" In order to facilitate new reporting requirements I will be needing a planned spend on all projects in process for Q2,Q3,
and Q4 of this year.
Also, if any spend will be pushed to next year, please indicate that as '2014 and beyond'. Please furnish all of the
information on the attached
spreadsheet. If the project listed is completed, please reply to this message with the MONTH/YEAR of completion and that will
close your
responsibility. If you have multiple projects, feel free to consolidate them on the spreadsheet." 
& Chr(13) & Chr(10) & " " & Chr(13) & Chr(10) & 
" Your reply is appreciated BY TUESDAY,  APRIL 2nd 2013. If you have any questions, feel free to eMail me any time. "
 & Chr(13) & Chr(10) & " " & Chr(13) & Chr(10) & 
" Regards," & Chr(13) & Chr(10) & " " & Chr(13) & Chr(10) & 
" (closing signature)"

This is my current label I have that is mapped to the email body. As you can see it is rather messy. I have used a utility like this with Apple in a Filemaker database that could do mass emails and it was MUCH easier. I could basically type at will and simply insert a variable wherever needed. IE

	(Greetings [customer], your order number is [order_no] and was shipped out on [ship_date])

Is there any such easier way to do this without having to submit to the draconian syntax in Text Boxes in Access?


How can I assign each row of a report to a string field to make up a body text variable?

The following code only gives me the last record's details ( name and adress).

strBodyText = name1 & " " & address

I need to create a variable with all the preceding records included as well

Do I need a For loop? And how should it be structured - I only have two fields in the report Name1 and address.



Apologies for this, their may well be solutions for my this on here already, but I'm quite new to both Access VBA programming (no training) and I've been tasked with achieving something that seems to require a fairly good of knowledge of both.

I need to send by email the individual group results of a report to each recipient on that report. The wish is for that email to have the report results in the email body, not as an attachment.

I have experience with SQL via a proprietary database design that our business runs on. I have a handle on that and I'm happy with how I will design the database. I'm at a testing/trial stage with access so far.

Basically I scrape our SQL database into csv then link the access table to that. No it's not possible to link the Access tables directly to the main database. I write the SQL that selectively does the scrape, so I have control over that. Becuase the scrape is one csv file, I have also created the access database as one table.

I have queries and reports that show the data I want to email. I have made the actual email as the top group in my report, from there I have more orders of group and sort.

In my experimenting I have been able to report the data by email address with page breaks, and had a little success in adapting some code, but not enough that it works. I have tried a form with a command button and an event procedure.

I really need help and anything would be appreciated. I have very little to go on and no training. I use Office 2003


Here my code for generating an email out of my database:

	Private Sub SendEmail2_Click()
Dim EmailApp, NameSpace, EmailSend As Object
Dim strTitle, strFn, strLN, strBody As String

Set EmailApp = CreateObject("Outlook.Application")
If EmailApp Is Nothing Then Set EmailApp = CreateObject("Outlook.Application")
Set NameSpace = EmailApp.GetNamespace("MAPI")
Set EmailSend = EmailApp.CreateItem(0)

strTitle = Me![Title]
strFn = Me![First Name]
strLN = Me![Last Name]
strBody = "Dear " & strTitle & " " & strFn & " " & strLN & "," & Chr(13) & Chr(13)
strBody = strBody & "Warm greetings!" & Chr(13) & Chr(13)
strBody = strBody & "My name is Lala." & Chr(13)
strBody = strBody & "I live in Lulu."
strBody = strBody & "Shipping method: " & [Position] & Chr(13)
strBody = strBody & "Date shipped: " & [Birthdate] & Chr(13)
strBody = strBody & "Tracking / Confirmation number: " & [ProfileID] & Chr(13)
strBody = strBody & "Sincerely," & Chr(13) & Chr(13)
strBody = strBody & "Acme Corporation"

If IsNull([Email]) Or ([Email]) = "" Then
       MsgBox "There is no E-mail address entered for this person!"
       Exit Sub
    With EmailSend
        .Subject = "Warm Greetings!"
        .To = Me.Email
        '.CC = ""
        '.From = ""
        .Body = strBody
        '.Attachments.Add "C:attachment.txt"
        '.Attach = strFilePath & "" & strFileName
        '.AttachFile strFilePath & "" & strFileName, strFileName
    End With
End If

Set EmailApp = Nothing
Set NameSpace = Nothing
Set EmailSend = Nothing

End Sub

What I would like to do is to get the message body from a textfile instead of entering it as a string directly into the code.
However, this method should be reliable in terms of format, e.g. I need to have linebreaks in the email exactly like in textfile, etc.

I would appreciate every help!

Not finding an answer? Try a Google search.