Solved

How to open an email with field values from a form

Posted on 2014-03-11
6
342 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
[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
  • 4
  • 2
6 Comments
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 39920761
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
ID: 39920766
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
ID: 39920794
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 57
ID: 39920839
<<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
ID: 39920848
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
ID: 39920869
I'm on my way.   Many thanks!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

749 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