Microsoft Outlook 9/10 Object

Posted on 2003-02-19
Medium Priority
Last Modified: 2010-04-17
I am having problems with Outlook 9 Object not being able to set the message format. I am sending automatic e-mails through Access with report attachments, when i send them though the attachments show up in the message body wich i dont want i want them in the header where the e-mail details are, can any one help with this?

It also needs to work in Outlook 10 aswell.

my current code is:

Function SendEMail(EmailTo As String, Optional EmailCc As String = "", Optional EmailSubject As String = "", Optional EmailMsg As String = "", Optional EmailAttach As String = "", Optional EmailDisplay As Boolean = False)
On Error GoTo ErrorLog
Dim MyOutlook As Outlook.Application
Dim mymail As Outlook.MailItem
MyBodyText = EmailMsg
    Set MyOutlook = New Outlook.Application
        Set mymail = MyOutlook.CreateItem(olMailItem)
            If EmailTo > "" Then mymail.To = EmailTo Else MsgBox "No E-mail address was specified": Exit Function
            If EmailCc > "" Then mymail.CC = EmailCc Else
            If EmailSubject > "" Then mymail.Subject = EmailSubject Else
            If EmailMsg > "" Then mymail.Body = EmailMsg Else
            If EmailAttach > "" Then mymail.Attachments.Add EmailAttach, olByValue: Kill EmailAttach Else
            If EmailDisplay = True Then mymail.Display Else mymail.Send
        Set mymail = Nothing
    Set MyOutlook = Nothing
Exit Function
TrapError Err.Description, Form.Name
Resume Next

End Function
Question by:Jim_Bob_Joe
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

Accepted Solution

NPluis earned 150 total points
ID: 7981761
Have you changed the position value?

"A positive value of Position represents an index to the character within the message text to be replaced by the attachment. The first text character has an index of 1. The value 0 indicates that the attachment is present but should not be made visible in the displayed message. The value –1 indicates that the attachment is not handled using the Position property."

If you want it work in different Outlook version I would recommend to use CDO.
LVL 14

Expert Comment

by:Tommy Kinard
ID: 7982285
The sub I use is below for sending e-mail, but I use the MAPI controls 6.0.

Private Sub Send_Mail()
    Dim CR As String
    Dim Spa As String
    Dim Sess As MAPISession
    Dim Mess As MAPIMessages
    Set Mess = MAPIMessages1
    Set Sess = MAPISession1
    CR = Chr$(13) & Chr$(10)
    Spa = "      "
    Sess.LogonUI = 1
    Sess.Action = 1
    If Err <> 0 Then
        MsgBox "Logon Failed : " & Err.Description
        Exit Sub
    End If
    Mess.SessionID = Sess.SessionID
    Mess.RecipAddress = Text1.Text
    Mess.MsgNoteText = GetHeader
    Mess.AttachmentType = mapData
    Mess.AttachmentPathName = "c:\save\" & Text2.Text & WOext
    Mess.AddressResolveUI = True
    On Error GoTo AA
    Sess.Action = 2
    Set Sess = Nothing
    Set Mess = Nothing
    On Error GoTo 0
    Exit Sub
    MsgBox "Possible cause for not finding attachment"
    On Error GoTo 0
End Sub

Author Comment

ID: 7992687
Thanx, it moved the attachment out of the way of my text what i wanted.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Make the most of your online learning experience.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

770 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