Solved

How to open an email with field values from a form

Posted on 2014-03-11
6
334 Views
Last Modified: 2014-03-11
Is it possible to open a New email (To: can be blank) via a form button, with selected control values appearing in the body of the email?  If so, please provide sample VBA code to do so.
0
Comment
Question by:David_W_R
  • 4
  • 2
6 Comments
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
Comment Utility
Here's one example:

Sub SendMessage(strTo As String, _
                               strSubject As String, strBody As String, strCC As String, _
                               Optional AttachmentPath)

    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem

    ' Create the Outlook session.
    Set objOutlook = CreateObject("Outlook.Application")

    ' Create the message.
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

    With objOutlookMsg
        ' Add the To recipient(s) to the message.
        .To_ = strTo
        .CC = strCC
        .BodyFormat = olFormatHTML
        .HTMLBody = strBody
        .Subject = strSubject

        ' Add attachments to the message, multiple attachments separated with ;
        If Not IsMissing(AttachmentPath) Then
            .Attachments.Add (AttachmentPath)
        End If

        .Display

    End With

    Set objOutlookMsg = Nothing
    Set objOutlook = Nothing

End Sub
0
 
LVL 57

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
Note BTW that this is an early bound example, so you need a reference set to Outlook.

You'd call this from a onclick event, passing the control value to the procedure.

Also note there are other ways to send mail, but you would need to provide the interface and then send the mail directly.

Jim.
0
 

Author Comment

by:David_W_R
Comment Utility
Just what I need if you can advise me as to how to define a data type?  e.g. Outlook.Application   (error: user-defined type not defined)
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 57

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
<<Just what I need if you can advise me as to how to define a data type?  e.g. Outlook.Application   (error: user-defined type not defined) >>

 You need to set a reference to Outlook in the VBA editor under tools/references.

Jim.
0
 
LVL 57

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
Or you can go late bound:

 Dim objOutlook as Object

 Set objOutlook = CreateObject("Outlook.Application")

and forgo the reference.

Jim.
0
 

Author Closing Comment

by:David_W_R
Comment Utility
I'm on my way.   Many thanks!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Display multiple images in report 12 82
#deleted rowsc access 2010 backend 4 32
Combobox issue 4 25
DCount using "OR" 4 16
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now