?
Solved

Microsoft Outlook 9/10 Object

Posted on 2003-02-19
3
Medium Priority
?
266 Views
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
ErrorLog:
TrapError Err.Description, Form.Name
Resume Next

End Function
0
Comment
Question by:Jim_Bob_Joe
3 Comments
 
LVL 2

Accepted Solution

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

MSDN:
"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.
0
 
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.Compose
    Mess.RecipAddress = Text1.Text
    Mess.MsgNoteText = GetHeader
    Mess.AttachmentType = mapData
    Mess.AttachmentPathName = "c:\save\" & Text2.Text & WOext
    Mess.AddressResolveUI = True
    Mess.ResolveName
    On Error GoTo AA
    Mess.Send
    Sess.Action = 2
    Set Sess = Nothing
    Set Mess = Nothing
    On Error GoTo 0
    Exit Sub
AA:
    Err.Clear
    MsgBox "Possible cause for not finding attachment"
    On Error GoTo 0
End Sub
0
 
LVL 3

Author Comment

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Make the most of your online learning experience.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Simple Linear Regression

569 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