-
1
- #1
The title of this post is probably a convoluded way of phrasing my dilemma (I've had more than my share of dilemmas lately with this database project I'm doing):
The code below, which is behind a command button in a form, generates an email with an image attachment that graphically appears in the body of the email. The attachment always saves itself into the Draft Items of Outlook whenever I .Display the email (it doesn't save if I send the email outright from the code).
I'm not sure if its the code below that's causing the attachemnt to save or if it's an Outlook setting. The code below was pieced together from one or two other old posts that I've found in tek-tips and I'm not really familiar with the procedures used to figure this out on my own.
Could you please let me know if you know what could be causing the problem?
If anyone knows how to direct Outlook, after Access creates the email, to delete the last draft item that was saved to the draft folder, then that would be a good workaround for me if I had to go that route.
Thanks very much for any help you can give.
The code below, which is behind a command button in a form, generates an email with an image attachment that graphically appears in the body of the email. The attachment always saves itself into the Draft Items of Outlook whenever I .Display the email (it doesn't save if I send the email outright from the code).
I'm not sure if its the code below that's causing the attachemnt to save or if it's an Outlook setting. The code below was pieced together from one or two other old posts that I've found in tek-tips and I'm not really familiar with the procedures used to figure this out on my own.
Could you please let me know if you know what could be causing the problem?
Code:
' Outlook objects
Dim objApp As Outlook.Application
Dim l_Msg As MailItem
Dim strRecipient As String
Dim colAttach As Outlook.Attachments
Dim l_Attach As Outlook.Attachment
Dim oSession As MAPI.Session
' CDO objects
Dim oMsg As MAPI.Message
Dim oAttachs As MAPI.Attachments
Dim oAttach As MAPI.Attachment
Dim colFields As MAPI.Fields
Dim oField As MAPI.Field
Dim strEntryID As String
' create new Outlook MailItem
Set objApp = CreateObject("Outlook.Application")
Set l_Msg = objApp.CreateItem(olMailItem)
' add graphic as attachment to Outlook message
' change path to graphic as needed
Set colAttach = l_Msg.Attachments
Set l_Attach = colAttach.Add("c:\CompanyLogo.jpg")
l_Msg.Close olSave
strEntryID = l_Msg.EntryID
Set l_Msg = Nothing
' *** POSITION CRITICAL *** you must dereference the
' attachment objects before changing their properties
' via CDO
Set colAttach = Nothing
Set l_Attach = Nothing
' initialize CDO session
On Error Resume Next
Set oSession = CreateObject("MAPI.Session")
oSession.Logon "", "", False, False
' get the message created earlier
Set oMsg = oSession.GetMessage(strEntryID)
' set properties of the attached graphic that make
' it embedded and give it an ID for use in an <IMG> tag
Set oAttachs = oMsg.Attachments
Set oAttach = oAttachs.Item(1)
Set colFields = oAttach.Fields
Set oField = colFields.Add(CdoPR_ATTACH_MIME_TAG, "image/jpeg")
Set oField = colFields.Add(&H3712001E, "myident")
oMsg.Fields.Add "{0820060000000000C000000000000046}0x8514", 11, True
oMsg.Update
' get the Outlook MailItem again
Set l_Msg = objApp.GetNamespace("MAPI").GetItemFromID(strEntryID)
' add HTML content -- the <IMG> tag
With l_Msg
strRecipient = txtUserID.Value
.To = strRecipient
If IsNull([txtAltRCName]) = True Then
.CC = [RC].Value
Else
.CC = "=" & [txtAltRCName].Value
.Recipients.ResolveAll
End If
.Recipients.ResolveAll
.Subject = "Monthly Quota Balances"
.HTMLBody = "<br><IMG align=baseline border=0 hspace=0 src=cid:myident>"
.Display
End With
If anyone knows how to direct Outlook, after Access creates the email, to delete the last draft item that was saved to the draft folder, then that would be a good workaround for me if I had to go that route.
Thanks very much for any help you can give.