Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Jun 2004
    Location
    Whistler, Br. Columbia, Canada
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    email form letter with fields from record as body of email

    I'd like to set up a button on a form that will take information from that record and send an email to the address on the form. I want the body of the email to be a form letter with fields from the record (Name, comments, etc). I have done this in the past by creating a report, printing it to pdf, and then emailing that, but now I'd like to send the info as the body of the email instead of as an attachment. I'd like the email to be formatted as well.

    I've done some reading about mail merges and I can see how to create a merge in Word that can access the database for the fields, but I'm not sure how to do a mail merge that results in emails instead of paper letters. Also, ideally the solution would be a one-click operation handled (from the user perspective) entirely within Access.

    Any one have a good place to start? I have limited experience in VBA and slightly more in Access in general.

    Thanks

  2. #2
    New Lounger
    Join Date
    Feb 2001
    Location
    Sacramento, California, USA
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Emailing from a form

    Take a look at the attached....it worked great for me for this purpose. You should be able to incorporate it into your process without much trouble.
    Attached Files Attached Files

  3. #3
    Lounger
    Join Date
    Jun 2004
    Location
    Whistler, Br. Columbia, Canada
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I ended up getting it with this code:

    Option Compare Database
    Option Explicit


    Sub SendMessagePos(Optional AttachmentPath)
    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookRecip As Outlook.Recipient
    Dim objOutlookAttach As Outlook.Attachment

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

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

    With objOutlookMsg
    ' Save the record if Dirty
    If [Forms]![comment card entry].Dirty = True Then
    [Forms]![comment card entry].Dirty = False
    End If

    ' Add the To recipient(s) to the message.
    Set objOutlookRecip = .Recipients.Add([Forms]![comment card entry]![Email])
    objOutlookRecip.Type = olTo

    ' Add the CC recipient(s) to the message.
    ' Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
    ' objOutlookRecip.Type = olCC

    ' Set the Subject, Body, and Importance of the message.
    .Subject = "Thank you for your recent feedback"
    .HTMLBody = " <p> " & [Forms]![comment card entry]![Reply] & " "

    '.Importance = olImportanceHigh 'High importance

    ' Add attachments to the message.
    If Not IsMissing(AttachmentPath) Then
    Set objOutlookAttach = .Attachments.Add(AttachmentPath)
    End If

    ' Resolve each Recipient's name.
    For Each objOutlookRecip In .Recipients
    objOutlookRecip.Resolve
    If Not objOutlookRecip.Resolve Then
    objOutlookMsg.Display
    End If
    Next
    .Send
    [Forms]![comment card entry]![SentGuest].Value = Date

    End With
    Set objOutlookMsg = Nothing
    Set objOutlook = Nothing
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •